Google Fight

Click the object, provide two keywords, it then performs a Google search and returns a victor, decided by number of search results.

Good for a few laughs

LSL

string word1;
string word2;
integer handle;
default
{
    touch_start(integer total_number)
    {
        word1="";
        word2="";
        llSay(0,"*GOOGLE-FIGHT*\nPlease say the first word...");
        handle=llListen(0,"",llDetectedKey(0),"");
    }

    listen(integer chan, string name, key id, string mess)
    {
        if (word1=="")
        {
            word1=mess;
            llSay(0,"Please say the second word...");
        }
        else
        {
            word2=mess;
            llHTTPRequest("http://php.zetaphor.net/googlefight.php?word1="+llEscapeURL(word1)+"&word2="+llEscapeURL(word2),[HTTP_METHOD,"GET"],"");
            llListenRemove(handle);
        }
    }

    http_response(key id, integer status, list meta, string body)
    {
        list results = llParseString2List(body,[","],[""]);
        integer w1 = (integer)llList2String(results,0);
        integer w2 = (integer)llList2String(results,1);
        if (w1>w2)
        {
            llSay(0,"'"+word1+"' wins with "+(string)w1+" results!\n'"+word2+"' - "+(string)w2+" results");
        }
        else
        {
            llSay(0,"'"+word2+"' wins with "+(string)w2+" results!\n'"+word1+"' - "+(string)w1+" results");            
        }     
    }

}

PHP

<?php
function getBetween($str, $start, $end) {
$startlen = strlen($start);
if (($startpos = strpos($str, $start)) !== false
&& ($endpos = strpos($str, $end)) !== false
&& ($skip = $startpos + $startlen) <= $endpos) {
return substr($str, $skip, $endpos - $skip);
} else {
return false;
}
}
function Google($word)
{
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".urlencode($word);
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.secondlife.com");
$body = curl_exec($ch);
curl_close($ch);
 
$json = json_decode($body);
return getBetween($body,'"estimatedResultCount":"','","currentPageIndex');
}
 
$result1 = Google($_GET['word1']);
$result2 = Google($_GET['word2']);
echo $result1.",".$result2;
?>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License