[英]How to get title from html file using directory - php
Fairly new to php, so bear with me. 相当新的PHP,所以忍受我。 I'm trying to figure out how to read a directory/folder and return both the filename/path and the title of that file into a li.
我正在试图找出如何读取目录/文件夹并将文件名/路径和该文件的标题返回到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>";
}
}
^code from miro(cheers/thanks) ^代码来自miro(欢呼/谢谢)
js.Fiddle link for visual: http://jsfiddle.net/AagGZ/547/ js.Fiddle链接视觉: http : //jsfiddle.net/AagGZ/547/
$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>";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.