1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[GET] PHP google results checker

Discussion in 'PHP & Perl' started by 5VM5UN6, Jan 4, 2010.

  1. 5VM5UN6

    5VM5UN6 Registered Member

    Joined:
    Jun 18, 2009
    Messages:
    51
    Likes Received:
    9
    Recently i've made myself a script to check google results for given keywords. Thought it may be useful to somebody.

    Script requires cURL to work.

    Code:
    <?php
    function GoogleResults($URL)
    {
    	$ch=curl_init();
    	curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/search?q='.urlencode($URL));
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	$output = curl_exec($ch);
    	curl_close($ch);
    	preg_match('/of \<b\>([0-9\,]+)\<\/b\>/si', $output, $m);
    	
    	if(isset($m[1]))
    		return $m[1];
    	preg_match('/of about \<b\>([0-9\,]+)\<\/b\>/si', $output, $m);
    	if(isset($m[1]))
    		return $m[1];
    }
    ?><html>
    <body>
    <div>
    <?php
    $list=null;
    if(isset($_POST['submit']))
    {
    	$keywords=explode("\n", $_POST['body']);
    	echo "<table><tr><td>Keyword</td><td>Broad</td><td>Exact</td><td>In title</td></tr>";
    	foreach($keywords as $value)
    	{
    		$value=trim($value);
    		if($value)
    		{
    			echo "<tr><td>".$value."</td><td><a href='http://www.google.com/search?q=".urlencode($value)."'>".GoogleResults($value)."</a></td><td><a href='http://www.google.com/search?q=".urlencode("\"".$value."\"")."'>".GoogleResults("\"".$value."\"")."</a></td><td><a href='http://www.google.com/search?q=intitle:".urlencode("\"".$value."\"")."'>".GoogleResults("intitle:\"".$value."\"")."</a></td></tr>\n";
    			$list.=$value."\n";
    		}
    	}
    	echo "</table>";
    }
    ?>
    </div>
    <form action="" method="post">
    <textarea name="body" rows="10" cols="40"><?php echo $list;?></textarea><br/>
    <input type="submit" name="submit"/>
    </form>
    </body>
    </html>
     
    • Thanks Thanks x 2
  2. dewancc

    dewancc Newbie

    Joined:
    Oct 23, 2009
    Messages:
    35
    Likes Received:
    4
    i will tryy... thanks man...
     
  3. Subject

    Subject Power Member

    Joined:
    Dec 26, 2007
    Messages:
    656
    Likes Received:
    303
    Location:
    Living With Articles!!
    but any difference between normal search and this script search?
     
  4. 5VM5UN6

    5VM5UN6 Registered Member

    Joined:
    Jun 18, 2009
    Messages:
    51
    Likes Received:
    9
    Script takes mulptiple keywords and checks them for broad, quoted and in title matches.
     
    • Thanks Thanks x 1