Florian: Seitentitel in Datei speichern?

Beitrag lesen

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

/*

  • The following constants do not require configuration. / $TERM_KEY = "term";  // key to be used in http-get for passing the term

$INDEX_FNAME = "index.txt";        //* file name of the index file

/*

  • get rid of slashes, convert to html-entities, strip excess whitespace */ function processFormInput($formInput) {         if (get_magic_quotes_gpc())                 $formInput = stripslashes($formInput);         $formInput = htmlentities($formInput);         $formInput = trim(ereg_replace("[[:space:]]+", " " , $formInput));         return $formInput; }

/*

  • Given a raw html document (as string), return its title.
  • This function may need to be modified if your web pages use automatically
  • generated titles. / function getTitle(&$doc) {         if (eregi("<!--html>(.)</html-->", $doc, $bodymatch))                 $body = trim(ereg_replace("[[:space:]]+", " " , $bodymatch[1]));         else                 $body = "";         if ($body == "")                 $body = "gefundener Text:";         return $body; }

/*

  • list_files:  for every file in the tree rooted at directory $d and whose *              name matches $m, adds the full path to that file to the *              array $l.  It assumes that the first two entries returned *              by readdir are "." and ".." which are ignored. *              If $x and $y are not empty strings, then for each file *              added to the list, the regexp $x is replaced by the string $y

*              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); }

/*

  • Makes a index file of your website (starting in the current directory and all subirectories).
  • Format is file name (relative to current directory), title, and then a tag/whitespace stripped
  • text of the file. Each of these fields occupy a line terminated with a \n.
  • Returns true if index file is successfully generated */ function makeIndexFile() {         global $FILE_MASK, $INDEX_FNAME, $HTTP_HOST,$SCRIPT_NAME;

$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; }

/*

  • searchMachine searches the index file, printing out a list of
  • links, titles, and excerpts of pages with the search term.
  • Takes variables: *    $searchTerm = term to search for
  • Returns an array: *    $n[0] = number of pages searched *    $n[1] = number of pages found *    $n[0] = -1 if index file could not be opened
  • Assumes that <span class="excerpt"> and <span class="highlight">
  • are defined in this page's style-sheet. / function searchMachine($searchTerm) {         global $INDEX_FNAME;         error_reporting(5);                                                                                                        // no error reporting for next line         $indexfileP = fopen($INDEX_FNAME, "r");                                                                // open index file         if (!$indexfileP)                                                                                                        // see if index file exists         {                 $n[0] = -1;                 return $n;         }         echo "<ul>\n";      //*         $searchTerm = "(" . quotemeta($searchTerm) . ")"; // so match result is always in \1         $n[0] = $n[1] = 0;                                                                                                        // [0]=num searched [1]=numfound         while (!feof($indexfileP))         {        $n[0]++;                 $reluri = chop(fgets($indexfileP, 512));                                                // read file line                 $body = chop(fgets($indexfileP, 512));                                                        // read title line                 $text = chop(fgets($indexfileP, 1048576));                                                // read html/php stripped text line                 if (eregi($searchTerm, $text, $match))                                                        // do search                 {                         $n[1]++;                         echo "<br><br><li><a href="index.php?page=$reluri">$body</a><br>\n";                        //**                         $textlength = strlen($text);                         if ($textlength > 400)  // if length > 400, truncate to 400 with first occurance of                         {                                                                                                                        // search term at position 60. (actually more complicated, but you figure it out)                                 $index = strpos($text, $match[1]) - 60;                                 $index = ($index < 0) ? 0 : $index;                                 if (($textlength-$index) < 400)                                         $index = $textlength - 400;                                 $text = substr($text, $index, 400);                                 if ($index > 0)                                                                                        //* add ... to begining of truncated text if truncated after pos 0                                         $text = "..." . $text;                                 if (($textlength-$index) > 400)                                                        //* add ... to end of truncated text if truncated before end                                         $text .= "...";                         }                         $text = eregi_replace($searchTerm,                                 '<span class="highlight">\0</span>', $text);                        //*  place found text in <spans> (be careful changing this one)                         echo "    <span class="excerpt">$text</span>\n";                        //** print stripped/truncated/tagged text                 }         }         fclose($indexfileP);         echo "</ul>\n";                                                                                                                //**         return $n; } ?>