this little snippet will extract the URLs of google results.
no - not only
from the results - it's actually a full search form.
“google results” makes use of the built-in PHP functions
urlencode( ),
trim( ),
fgets( ),
strpos( ) and
explode( ).
01 <?php
02
03 // lixlpixel google search
04 // rips the google result page apart and extracts the results
05
06 echo '
07 <h1>lixlpixel google search</h1>';
08
09 if(!isset($_POST['q']))
10 {
11 echo '
12 <form action="" method="post">
13 <fieldset>
14 <input type="text" name="q" />
15 </fieldset>
16 <fieldset>
17 <input type="submit" value="search" />
18 </fieldset>
19 </form>
20 ';
21 }else{
22 // this would be the URL if you want the results on page 2, 3 ... where $_POST['p'] is multiple of 10
23 // $off_site = 'http://www.google.com/search?q='.urlencode($_POST['q']).'&start='.$_POST['p'];
24 $off_site = 'http://www.google.com/search?q='.urlencode($_POST['q']).'&ie=UTF-8&oe=UTF-8';
25 $fp = fopen ($off_site, 'r') or die('Unable to open file '.$off_site.' for reading');
26 while (!feof ($fp))
27 {
28 $buf = trim(fgets($fp, 4096));
29 $pos = strpos($buf,'<p class=g>');
30 if($pos !== false)
31 {
32 $parts = explode('<p class=g>',$buf);
33 $parts2 = explode('http://',$parts[1]);
34 $parts3 = explode('>',$parts2[1]);
35 echo '
36 <a href="http://'.$parts3[0].'>'.$parts3[0].'</a><br />';
37 }
38 }
39 }
40
41
42 ?>