无论如何,例如当我导航到http://example.com/links/pages/index.html
时我在/ pages目录中有4个.html文件,名称为page1.html,page2.html,page3.html,page4.html
然后index.html必须显示此/ pages目录中存在的页面列表?没有我自己手动将它们列在index.html上。当我在/ pages目录
创建一个新页面时,我只希望它们在index.html中列出这里有一些例子希望它有所帮助:http://plnkr.co/edit/kIiod2DR6zgSpmuUNsUi?p=preview
或此示例
<!-- This is index.html page in this directory http://example.com/links/pages/index.html -->
<html>
<head>
</head>
<body>
<!-- here must be listed pages that is exist in this directory /pages -->
<!-- example for to be listed -->
<ul>
<li><a href="page1.html">page 1</a></li>
<li><a href="page2.html">page 2</a></li>
<li><a href="page3.html">page 3</a></li>
<li><a href="page4.html">page 4</a></li>
</ul>
</body>
</html>
答案 0 :(得分:1)
这是一个例子:
在文件夹&#34;页面&#34;你有:
index.php将是:
<html>
<head>
</head>
<body>
<!-- here must be listed pages that is exist in this directory /pages -->
<?php
$dir = 'pages';
$pages = array_values(array_diff(scandir($dir), array('..', '.')));
?>
<ul>
<?php
foreach ($pages as $page) {
$name = str_replace('.html', '', $page);
echo "<li><a href=\"$page\">$name</a></li>";
}
?>
</ul>
</body>
</html>
输出将是:
<html>
<head>
</head>
<body>
<ul>
<li><a href="page1.html">page1</a></li>
<li><a href="page2.html">page2</a></li>
<li><a href="page3.html">page3</a></li>
</ul>
</body>
</html>