communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "forms" - download "google results" - open demo of "google results"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

forms - google results was created/last modified on Tue 27 Apr 2004 12:39 AM

this little snippet will extract the URLs of google results.
no - not only from the results - it's actually a full search form.
      
<?php
      
   
// lixlpixel google search
   // rips the google result page apart and extracts the results
   
   
echo '<html>
   <head>
      <title>lixlpixel google search</title>
   </head>
   <body>'
;
      
   if(!isset(
$_POST['q']))
   {
       echo
'
       <form action="'
.$_SERVER['PHP_SELF'].'" method="post">
           <input type="text" name="q">
           <input type="submit" value="search">
       </form>
   '
;
   }else{
       
// this would be the URL if you want the results on page 2, 3 ... where $_POST['p'] is multiple of 10
       // $off_site = 'http://www.google.com/search?q='.urlencode($_POST['q']).'&start='.$_POST['p'];
      
$off_site = 'http://www.google.com/search?q='.urlencode($_POST['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>';
           }
       }
   }
      
   echo
'
   </body>
   </html>'
;
      
?>

learn more about some of the PHP functions used in this snippet: die, echo, else, explode, extract, feof, fgets, file, fopen, for, isset, strpos, trim, urlencode, while

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari