Skip to content

Instantly share code, notes, and snippets.

@siddartha
Created April 29, 2013 21:31
Show Gist options
  • Save siddartha/5484958 to your computer and use it in GitHub Desktop.
Save siddartha/5484958 to your computer and use it in GitHub Desktop.
<?php
// http://clients1.google.com/complete/search?hl=fr&output=toolbar&q=gestion%20des%20logs
$query = urlencode($_GET['q']);
$uri = "http://clients1.google.com/complete/search?hl=fr&output=toolbar&q=".$query;
/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$xmlObject = new SimpleXMLElement(utf8_encode(get_data($uri)));
foreach ($xmlObject as $node) {
echo "<br/>\n" . utf8_decode((string) $node->suggestion->attributes()->data[0]) . ' ' . (string) $node->num_queries->attributes()->int[0];
}
print_r($results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment