2021年9月29日 星期三

[PHP] 掃描子目錄, 自動建立連結標籤

掃描子目錄, 自動建立連結標籤, 例如將  startbootstrap 系列的範例解開放在子目錄下:

以下是 index.php 的內容

 

 <!DOCTYPE html>
<html>
       
<head>
    <title>
        startbootstrap
    </title>
</head>
 
<body>
    <center>
        <h1 style="color:green;">
            startbootstrap
        </h1>
        
<?php
    $path = './';
    $results = scandir($path);

    foreach ($results as $result) {
        if ($result === '.' or $result === '..') continue;

        if (is_dir($path . '/' . $result)) {            
            echo '<a href='.$result.'>'.$result.'</a></br>';
        }
    }
?>
    </center>
</body>
 
</html>

沒有留言:

張貼留言