whether can combine 2+ google api url for one json_decode foreach process?
<?php
$url = "http://ajax.googleapis.com/ajax/services/search/news?v=1.0&rsz=large&topic=h&key={key-id}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
$body = curl_exec($ch);
curl_close($ch);
$data = json_decode($body);
foreach ($data->responseData->resul开发者_StackOverflow中文版ts as $result) {
...
}
$url2 = "http://ajax.googleapis.com/ajax/services/search/news?v=1.0&rsz=large&topic=h&start=8&key={key-id}";
$ch = curl_init();
...
foreach
...
?>
I want to make an easy google search to show fresh news. I only know how to use &start8
to begin next 8 news items... Is there any way to combine 2+ $url
that only one json_decode foreach can process all the results. Because the json callback structure are similar. Just define one foreach ($data->responseData->results as $result)
... Thanks.
json_decode gives arrays So you could just use array_merge assuming keys are unique
精彩评论