Hi,
Has anyone manage to show the phoneNumbers, with the CURL method?
I¹ve done many tests, following the reference, but I didn¹t find a working
example on the web.
Normally, it should be something like this: $sr['phoneNumbers'][0] or like
this $sr['phoneNumbers']['number'][0]
I manage to count how many records are in count($sr['phoneNumbers'][0] and
it says 1 or 2.
Any ideas, examples, or links would be appreciated.
<?php
require_once 'JSON.php';
if(isset($_GET['q'])) {
$start = isset($_GET['start']) ? $_GET['start'] : 0;
$url =
'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q='.urlencode($
_GET['q']).'&rsz=small&start='.$start;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);
curl_close($ch);
$body = json_decode($body);
$i = 0;
$search_results = array();
foreach($body->responseData->results as $r) {
$search_results['results'][$i]['title'] = $r->title;
$search_results['results'][$i]['phoneNumbers'] = $r->phoneNumbers;
$search_results['results'][$i]['type'] = $r->type;
$search_results['results'][$i]['number'] = $r->number;
$i++;
}
foreach($search_results['results'] as $sr) {
echo $sr['title']."<br>";
echo count($sr['phoneNumbers'][0])." <- 1 : gives 1 result. meaning
there is 1 phone number<br>"; // best:
echo count($sr['phoneNumbers']['number'])." <- 2<br>"; // gives 0
results, but doesn't give an error
echo count($sr['phoneNumbers']['number'][0])." <- 3<br>"; // gives 0
results, but doesn't give an error
echo $sr['phoneNumbers']." <- 4<br>"; // doesn't give an error but
doesn't give a number.
echo $sr['phoneNumbers']['number']." <- 5<br>"; // empty line
echo $sr['phoneNumbers']['number'][0]." <- 6<br>"; // empty line
// this gives error echo count($sr['phoneNumbers'][0]['number'])."<br>";
// this gives error echo $sr['phoneNumbers'][0]."<br>";
// this gives error echo $sr['phoneNumbers'][0]['number']."<br>";
}
}
?>
On 25/03/09 18:01, "comocomo" <[email protected]> wrote:
> Hi Jeremy
>
> For the number, it didn¹t work
>
> So, I created a new file, simplified with all the tests that semi work, and
> don¹t work.
>
> http://allmybookings.com/apilocal/search-results.php?q=restaurants+brussels
>
> The code:
>
> <?php require_once 'JSON.php'; if(isset($_GET['q'])) { $start =
> isset($_GET['start']) ? $_GET['start'] : 0; $url =
> 'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q='.urlencode($_G
> ET['q']).'&rsz=small&start='.$start; $ch = curl_init(); curl_setopt($ch,
> CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $body =
> curl_exec($ch); curl_close($ch); $body = json_decode($body); $i =
> 0; $search_results = array(); foreach($body->responseData->results as
> $r) { $search_results['results'][$i]['title'] = $r->title;
> $search_results['results'][$i]['phoneNumbers'] = $r->phoneNumbers;
> $search_results['results'][$i]['type'] = $r->type;
> $search_results['results'][$i]['number'] = $r->number; $i++; }
> foreach($search_results['results'] as $sr) { echo
> $sr['title']."<br>"; echo count($sr['phoneNumbers'][0])." <- 1 : gives
> 1 result. meaning there is 1 phone number<br>"; // best: echo
> count($sr['phoneNumbers']['number'])." <- 2<br>"; // gives 0 results, but
> doesn't give an error echo count($sr['phoneNumbers']['number'][0])." <-
> 3<br>"; // gives 0 results, but doesn't give an error echo
> $sr['phoneNumbers']." <- 4<br>"; // doesn't give an error but doesn't give a
> number. echo $sr['phoneNumbers']['number']." <- 5<br>"; // empty line
> echo $sr['phoneNumbers']['number'][0]." <- 6<br>"; // empty line // this gives
> error echo count($sr['phoneNumbers'][0]['number'])."<br>"; // this gives
> error echo $sr['phoneNumbers'][0]."<br>"; // this gives error echo
> $sr['phoneNumbers'][0]['number']."<br>"; } } ?>
>
>
> What could it be? ;o)
>
> Thanks again,
>
> Sebastian
>
>
>
> On 25/03/09 17:15, "Jeremy Geerdes" <[email protected]> wrote:
>
>> Try $sr['phoneNumbers'][0]['number']
>>
>>
>> Jeremy R. Geerdes
>> Effective website design & development
>> Des Moines, IA
>>
>> For more information or a project quote:
>> http://jgeerdes.home.mchsi.com
>> http://jgeerdes.blogspot.com
>> http://jgeerdes.wordpress.com
>> [email protected]
>>
>> Unless otherwise noted, any price quotes contained within this communication
>> are given in US dollars.
>>
>> If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan
>> Church!
>>
>> And check out my blog, Adventures in Web Development, at
>> http://jgeerdes.blogspot.com !
>>
>>
>>
>> On Mar 25, 2009, at 11:09 AM, sebastian de comocomo wrote:
>>
>>> 'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q='.urlencode($
>>> _GET['q']).'&rsz=large&start=
>>
>>
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google AJAX APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-AJAX-Search-API?hl=en
-~----------~----~----~----~------~----~------~--~---