NameSilo

PHP: Grab Search Engine Results

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch
Have you ever needed to find the amount of results for certain keywords from all three major search engines? (Google, MSN, Yahoo)*?

Well, with this you can find all those figures within one page!

* If you want a new search engine added please reply here with the url.

Demo:
http://mattjewell.com/namepros/seresults/

PHP:
<?php

/*
	Code written by Matt Jewell (http://mattjewell.com) for http://namepros.com
	Namepros username: "Matthew." (id #45276 http://www.namepros.com/member.php?u=45276)
	
	Feel free to redistribute but please link back to both mattjewell.com and the namepros topic.
	Link backs are NOT required for personal or comercial use however are always appreciated.
*/


if(strlen($_GET['keywords']) > 0 && isset($_GET['search']))
{
	echo '<h1>Searching for <em>' . stripslashes($_GET['keywords']) . '</em></h1>';
	
	
	ob_start();
	$keywords = str_replace(' ', '+', stripslashes($_GET['keywords']));
		
	// provider name => (string pattern, search url)
	$engines = array('MSN'      => array('Page [0-9] of ([^\.]+) results', 'http://search.live.com/results.aspx?q='),
					 'Google'   => array('Results <b>[0-9]+<\/b> - <b>[0-9]+<\/b> of about <b>([^\.]+)<\/b> for', 'http://google.com/search?q='),
					 'Yahoo'    => array('[0-9]+ - [0-9]+ of about ([^\.]+) for', 'http://search.yahoo.com/search?p=')
					 );
			
	foreach($engines as $key => $value)
	{
		
		if(preg_match("/{$value[0]}/i", file_get_contents($value[1] . $keywords), $matches))
		{
			echo "<strong>$key</strong>: {$matches[1]} results found<br />";
		}
		else
		{
			echo "<strong>$key</strong>: No Matches";
		}
		ob_flush();
		flush();
	}
}
else
{
	if(!isset($_GET['search']))
	{
		?>
		
		<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="get">
			Keywords: <input type="text" name="keywords" value="" /><br />
					  <input type="submit" name="search" value="Search" />
		</form>
		
		<?php
	}
	else
	{
		echo 'You did not enter any keywords';
	}
}

?>

Enjoy!

Matt
 
Last edited:
1
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Nice one Matt :)
 
0
Close
Great one.
You're always sharing great scripts...

We're glad that you're fond of this member, but please give some rep points to some other members before giving it to Matthew. again.
 
0
Close
thanks very much :)
 
0
Close
Very nice and simple well done :D
 
0
Close
Great Job on this. I am glad that someone made this.
-CP
 
0
Close
Just glad it came in handy to someone :)

Matt
 
0
Close
Thanks, thats quite useful.
 
0
Close
Nice simple code. Thanks. ;)
 
0
Close
0
Close
I am surprised how few results there are for 'google' on msn.
 
0
Close
What's even more intereting is that if we go to msn search manually and search for google, it comes up with a lot more results.

Bug ;)

I will look into later, i must do some work for now however it seems fine for anything other than the word "google". (which is stupid as it should make no difference...)
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back