Alright, I'm using the Blekko search API:
http://blekko.com/ws/?q=hello+%2Fjson
how would I go about parsing it ?
I have no experience of parsing JSON from PHP, so I'd appreciate a little help, and the json_decode()
docs failed to explain everything for me, particularly getting the data inside RESULT
. :) You know, [ and ].
Could you help pointing me in the right direction ? :)
Thank you, you're all so helpful! :)
Here's the code to access the API. You should enter your own error/unexpected results handling where i've left the comments.
$data = file_get_contents('http://blekko.com/ws/?q=hello+%2Fjson');
if(!empty($data)){
$data = json_decode($data);
if(!empty($data->ERROR)){
// Error with API response.
} else {
$data = $data->RESULT;
if(empty($data)){
// No results.
} else {
// Uncomment the line below to see your data
// echo '<pre>' . print_r($data) . '</pre>';
foreach($data AS $key => $val){
echo $val->short_host . '<br />';
}
}
}
} else {
// Failed to retrieve data.
}