On the first point, you're almost there ... just reorganize the code so that you pull the title out of the target file before you generate the link.
$verzeichnis = dir(".");
$endung = ".htm";
while($datei = $verzeichnis->read()) {
if(substr($datei,strlen($endung)(-1)) == $endung)
{
$fp = fopen($datei,"r");
while (!feof($fp)) {
$linie = fgets($fp, 1024);
if(eregi("<title>(.)</title>", $linie, $title))
break;
}
echo "<A HREF=\"$datei\">$linie[1]</A> <BR> ";
fclose($fp);
}
}
$verzeichnis->close();
On the second point, I'm not sure I understand what you want to do. Obviously you can open a cache file with fopen() and save the HTML to that file using fwrite instead of echo, but if you put new file(s) into the directory, the cached index that you have created will no longer be valid.