Hi
I took a quick look in the archives, but didn't find an answer
to this one.
I'd like to display a list of HTML files in a directory, showing the
author's name between brackets after the file name. I can successfully
extract the TITLE section, but no luck with the AUTHOR part. Any idea
why?
<?php
$body = "<h1>Documents</h1>";
$dir = opendir(".");
while ($item = readdir($dir)) {
//Only HTM(L) files
if(substr($item,-5) == ".html" || substr($item,-4) == ".htm") {
$fp = fopen($item, "r");
$contents = fread($fp, filesize($item));
fclose($fp);
//Works OK to extract TITLE
eregi("<title>(.+)</title>", $contents, $regs);
$file[$item] = $regs[1];
//Doesn't work
//eregi("<meta name=\"author\" content=\"(.+)\">', $contents,
$regs);
//Doesn't work
eregi('<meta name="author" content="(.+)">', $contents, $regs);
If ($regs[1])
$author[$item] = "(Author unknown)";
else
$author[$item] = "(" . $regs[1] . ")";
}
}
$body .= "<ul>\n";
foreach ($file as $item => $title) {
$body .= "<li><a href=\"" . $item . "\">" . $file[$item] . "</a> " .
$author[$item];
}
$body .= "</ul>\n";
print $body;
?>
FWIW, I tried making eregi non-greedy using (.+?) or ([^"].+), and
also used double quotes (shown above), all to no avail.
Any tip much appreciated.
Thank you
JD.