Seitentitel in Datei speichern?
Florian
- php
Wer kann mir helfen das dieser Auszug meines Scripts statt als Name "gefundener Text" sondern den Namen einer indexierten Webseite in einer Datei Speichert? Bitte helft mir, denn ich habe schon alles versucht!
{ if (eregi("<!--html>(.*)</html-->", $doc, $bodymatch)) $body = trim(ereg_replace("[[:space:]]+", " " , $bodymatch[1])); else $body = ""; if ($body == "") $body = "gefundener Text:"; return $body; }
und hier das ganze Script:
<?PHP //** comments with two stars indicate printing lines that may be modified //* indicates other lines that may be modified
/*
$INDEX_FNAME = "index.txt"; //* file name of the index file
/*
/*
/*
* John Bzrustowski, Friday, October 20, 2000 */ function list_files(&$l, $d, $m, $x, $y) { $h = opendir ($d); if ($h) { readdir ($h); // get rid of "." and ".." readdir ($h); while ($f = readdir ($h)) { $f = $d . "/" . $f; if ( is_dir ($f) ) { list_files ($l, $f, $m, $x, $y); } elseif ( ereg ($m, $f) ) { $l[ count ($l) ] = ereg_replace ($x, $y, $f); } } closedir ($h); } return count ($l); }
/*
$baseURI = "http://$HTTP_HOST$SCRIPT_NAME"; $baseURI = substr($baseURI, 0, strrpos($baseURI, "/"))."/";
ignore_user_abort(true); error_reporting(5); // no error reporting for next line $indexfileP = fopen($INDEX_FNAME, "w"); // write to temporary file if (!$indexfileP) return false; flock($indexfileP, 2); $files = array(); $n = list_files($files, ".", $FILE_MASK, "^\./", ""); for($i=0; $i<$n; $i++) { fwrite($indexfileP, $files[$i]); fwrite($indexfileP, "\n"); $file = implode("", file($files[$i])); fwrite($indexfileP, getTitle($file)); fwrite($indexfileP, "\n"); $file = strip_tags($file); // remove php/html tags $file = trim(ereg_replace("[[:space:]]+", " " , $file)); // reduce white space to single spaces fwrite($indexfileP, $file);
if ($i != $n) fwrite($indexfileP, "\n"); } fclose($indexfileP);
return true; }
/*
Hallo!
Wer kann mir helfen das dieser Auszug meines Scripts statt als Name "gefundener Text" sondern den Namen einer indexierten Webseite in einer Datei Speichert?
Bitte helft mir, denn ich habe schon alles versucht!
Ich habe nicht verstanden, was Du möchtest, deshalb gehe ich mal nach dem Betreff.
{
if (eregi("<!--html>(.*)</html-->", $doc, $bodymatch))
$body = trim(ereg_replace("[[:space:]]+", " " , $bodymatch[1]));
else
$body = "";
if ($body == "")
$body = "gefundener Text:";
return $body;
}
Wenn man sich diesen Teil mal anschaut, eigentlich ganz einfach anzupassen, ohne Ahnung vin regulären Ausdrücken zu haben.
$doc = "seite.html";
eregi("<!--title>(.*)</title-->", $doc, $titelmatch)
$title = trim($titelmatch[1]); // Leerzeichen links und rechts entfernen
if($titlematch != "")
{
echo $title;
}
else
{
echo "Die Seite hat kein Titel";
}
Mit ein paar regulären Ausdrücken und/oder könnte man noch austesten, wie die Titel aussieht.
MfG, André Laugks