Unstoppable Domains

PHP: Grab Search Engine Results

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Nice one Matt :)
 
0
•••
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
•••
thanks very much :)
 
0
•••
Very nice and simple well done :D
 
0
•••
Great Job on this. I am glad that someone made this.
-CP
 
0
•••
Just glad it came in handy to someone :)

Matt
 
0
•••
Thanks, thats quite useful.
 
0
•••
Nice simple code. Thanks. ;)
 
0
•••
0
•••
I am surprised how few results there are for 'google' on msn.
 
0
•••
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
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back