Created
April 29, 2013 17:28
-
-
Save siddartha/5483218 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://clients1.google.com/complete/search?hl=fr&output=toolbar&q=gestion%20des%20logs | |
$q = $argv[1]; | |
$url = "http://clients1.google.com/complete/search?hl=fr&output=toolbar&q=".urlencode($q); | |
/* 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; | |
} | |
$data = get_data($url); | |
$xmlObject = new SimpleXMLElement($data); | |
//var_dump($xmlObject); | |
foreach ($xmlObject as $node) { | |
foreach ($node as $d){ | |
$key = $d['data']; | |
$req = $d['int']; | |
echo $key." ".$req; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No-CLI here: https://gist.github.com/siddartha/5484958
Thx @Malaiac & @JeuneVeteran