3

对php相当陌生,所以请多多包涵。我试图弄清楚如何读取目录/文件夹并将文件名/路径和该文件的标题返回到一个 li。

$handle = opendir('.'); 
while (false !== ($file = readdir($handle))){ 
  $extension = strtolower(substr(strrchr($filename, '.'), 1)); 
  if($extension == 'html' || $extension == 'htm' || $extension == 'php'){ 
      echo "<a href='".$filename."'><li class='"iso_block"'><span>"**Title Tag Here**"</span></li></a>";
  } 
}

^ 来自 miro 的代码(欢呼/感谢)

用于视觉的 js.Fiddle 链接:http: //jsfiddle.net/AagGZ/547/

4

1 回答 1

1
$handle = opendir('.');
$dom    = new DOMDocument();

while (false !== ($file = readdir($handle))){ 
    $extension = strtolower(substr(strrchr($file, '.'), 1));
    if ($extension == 'html' || $extension == 'htm' || $extension == 'php') {
        $title = 'Untitled Document';

        if($dom->loadHTMLFile($urlpage)) {
            $list = $dom->getElementsByTagName("title");
            if ($list->length > 0) {
                $title = $list->item(0)->textContent;
            }
        }

        echo "<a href='$filename'><li class='iso_block'><span>$title</span></li></a>";
    } 
}
于 2013-05-28T05:10:54.203 回答