View Single Post
Old 02-13-2007, 07:04 AM   · #1
Matthew.
Stud Sausage
 
Location: England
Trader Rating: (25)
Join Date: Dec 2006
Posts: 1,545
NP$: 32.41 (Donate)
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
Adoption Breast Cancer Breast Cancer Cancer Survivorship
PHP: Grab Search Engine Results

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 Code:
<?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


Please register or log-in into NamePros to hide ads
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline   Reply With Quote
Site Sponsors
Find out how! NameChatter http://www.mobisitetrader.com/
Advertise your business at NamePros
All times are GMT -7. The time now is 11:21 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.