Tag Archive for google

How to Write Your Own IM Bot in Less Than 5 Minutes

<?php
// Get all the related keywords from Google Suggest
$u = "http://google.com/complete/search?output=toolbar";
$u = $u . "&q=" . $_REQUEST['msg'];

// Using the curl library since dreamhost doesn't allow fopen
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $u);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$xml = simplexml_load_string(curl_exec($ch));
curl_close($ch);

// Parse the keywords and echo them out to the IM window
$result = $xml->xpath('//@data');
while (list($key, $value) = each($result)) {
echo $value ."<br>";
}
?>

source

Google Favicon

<img src="http://www.google.com/s2/favicons?domain=simonwillison.net" />

source

Which Search Engine is referring users to your site. Displays the keyword used.

if ((isset($_SERVER['HTTP_REFERER'])) and ($_SERVER['HTTP_REFERER']!= '')) {
$keywords = "";
$url = urldecode($_SERVER['HTTP_REFERER']);

// Google
if (eregi("www.google",$url)) {
preg_match("'(?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'Google';
}

// Yahoo
if ((eregi("yahoo.com",$url)) or (eregi("search.yahoo",$url))) {
preg_match("'(?¦&)p=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'Yahoo';
}

// MSN
if (eregi("search.msn",$url)) {
preg_match("'(?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'MSN';
}

// AllTheWeb
if (eregi("www.alltheweb",$url)) {
preg_match("'(?¦&)q=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'AllTheWeb';
}

// Looksmart
if (eregi("looksmart.com",$url)) {
preg_match("'(?¦&)qt=(.*?)(&¦$)'si", " $url ", $keywords);
$search_engine = 'Looksmart';
}

if (($keywords[2]!= '') and ($keywords[2]!= ' ')) {
$keywords = preg_replace('/"¦'/', '', $keywords[2]); // Remove quotes
}
echo $keywords;
echo $search_engine;
}

source

google.loader.ClientLocation to get a person’s lat/long using their IP address

if (GBrowserIsCompatible()) {
var map = new google.maps.Map2(document.getElementById("my-googlemap"));
if (google.loader.ClientLocation &&
google.loader.ClientLocation.address.country_code == "US" &&
google.loader.ClientLocation.address.region) {
// geo locate was successful and user is in the states
map.setCenter(
new google.maps.LatLng(google.loader.ClientLocation.latitude,
google.loader.ClientLocation.longitude
), 8
);
// do the rest of your map stuff here
}
}

source

Find the Latitude and Longitude of a ZIP/Postcode using Google

function GetLatLong($postcode){
$myKey = 'Your_Google_API_Key_Here';
$URL = "http://maps.google.co.uk/maps/geo?q=" . urlencode($postcode) . "&output=json&key=".$myKey;

$data = file($URL);
if($data){
$data = json_decode($data[0]);

$long = $data->Placemark[0]->Point->coordinates[0];
$lat = $data->Placemark[0]->Point->coordinates[1];

return array('Latitude'=>$lat,'Longitude'=>$long);

}else return false;

}

source

Google AJAX API Language e Prototype.js

/*
** @name	 : translate()
** @description  : translate
*/
function translate() {
$$('[rel="translate"]').each(
function(e) {
google.language.translate(e.innerHTML, 'it', 'en',
function(result) {
if (result.translation) {
e.innerHTML = result.translation;
} else {
alert( 'Translate Error!

' + result.error.message );
}
}
);
}
);
}

source

Google Analytics urchin.js Script

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "{0}";
urchinTracker();
</script>

source

Google Analytics ga.js Script

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("{0}");
pageTracker._initData();
pageTracker._trackPageview();
</script>

source

Launch Google Search in default Browser

/// <summary>
/// Class to launch Google Search in default browser.
/// </summary>
public static class Google {
/// <summary>
/// Launches Google Search in default browser, and escapes string according to: <a href="http://code.google.com/apis/searchappliance/documentation/46/xml_reference.html#appendix_url_escaping" >http://code.google.com/apis/searchappliance/documentation/46/xml_reference.html#appendix_url_escaping</a>
/// </summary>
/// <param name="searchQuery">The search query.</param>
public static void SearchGoogle(string searchQuery) {
string fixedSearchQuery = null;

foreach (char character in searchQuery) {
if (Char.IsLetterOrDigit(character)) {
fixedSearchQuery += character;
} else if (character == Char.Parse(" ")) {
fixedSearchQuery += "+";
} else {
fixedSearchQuery += Uri.HexEscape(character);
}
}

string url = @"http://www.google.com/search?hl=en&q=" + fixedSearchQuery;

try {
Process.Start(url);
} catch { }
}
}

source

Google Analytics without Javascript

$var_utmac=GOOGLE_ANALYTICS_CODE; //enter the new urchin code
$var_utmhn=WEB_DOMAIN; //enter your domain
$var_utmn=rand(1000000000,9999999999);//random request number
$var_cookie=rand(10000000,99999999);//random cookie number
$var_random=rand(1000000000,2147483647); //number under 2147483647
$var_today=time(); //today
$var_referer=$_SERVER['HTTP_REFERER']; //referer url

$var_uservar=$storeinfo["storeid"]; //enter your own user defined variable
$var_utmp="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

$urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=1&utmn='.$var_utmn.'&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn='.$var_utmhn.'&utmr='.$var_referer.'&utmp='.$var_utmp.'&utmac='.$var_utmac.'&utmcc=__utma%3D'.$var_cookie.'.'.$var_random.'.'.$var_today.'.'.$var_today.'.'.$var_today.'.2%3B%2B__utmb%3D'.$var_cookie.'%3B%2B__utmc%3D'.$var_cookie.'%3B%2B__utmz%3D'.$var_cookie.'.'.$var_today.'.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D'.$var_cookie.'.'.$var_uservar.'%3B';

$handle = fopen ($urchinUrl, "r");
$test = fgets($handle);
fclose($handle);

source