Tutorials Infos - Anleitungen - Hilfe - Dreamcodes
 

Google Top10

Manchmal möchte man sich zu einem Suchbegriff nur die ersten 10 Webseiten ohne weitere Infos aus dem Suchindex von Google anzeigen lassen. Dieses Script hilft Ihnen dabei.

Script:

<?php

   error_reporting(E_ALL);

   if(!isset($q)) {
      echo "<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">
             <input type=\"text\" name=\"q\">
             <input type=\"submit\" value=\"search\">
            </form>";
   }
   else {
      $off_site = "http://www.google.com/search?q=".urlencode($q)."&ie=UTF-8&oe=UTF-8";
      $fp = fopen ($off_site, "r") or die("Unable to open file ".$off_site." for reading");

      while (!feof ($fp)) {
         $buf = trim(fgets($fp, 4096));
         $pos = strpos($buf,"<p class=g>");

         if($pos !== false) {
            $parts = explode("<p class=g>", $buf);
            $parts2 = explode("http://", $parts[1]);
            $parts3 = explode(">", $parts2[1]);
            echo "<a href=\"http://".$parts3[0]."\" target=\"_blank\">".$parts3[0]."</a><br>";
         }
      }
   }

?>


   error_reporting(E_ALL);

   if(!isset($q)) {
      echo "<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">
             <input type=\"text\" name=\"q\"><br />
             <input type=\"submit\" value=\"Google    Suche\">
            </form>";
   }
   else {
      $off_site = "http://www.google.de/search?q=".urlencode($q)."&ie=UTF-8&oe=UTF-8";
      $fp = fopen ($off_site, "r") or die("Unable to open file ".$off_site." for reading");

      while (!feof ($fp)) {
         $buf = trim(fgets($fp, 4096));
         $pos = strpos($buf,"<p class=g>");

         if($pos !== false) {
            $parts = explode("<p class=g>", $buf);
            $parts2 = explode("http://", $parts[1]);
            $parts3 = explode(">", $parts2[1]);
            echo "<a href=\"http://".$parts3[0]."\" target=\"_blank\">".$parts3[0]."</a><br>";
         }
      }
   }

?>

 
ID: 685
eingestellt am: 11.02.2005
Autor: NA
Status zum lesen: Gast
gelesen: 8311
Webseite: www.dreamcodes.com
[Drucken]