Hi,

could anyone help me out with this?

I've tried everything I can imagine.

I suppose this is correct:

echo count($sr['phoneNumbers'][0]);

To see if there are any phone numbers in the variable, isn't it?

If so, how do I get the number?

Thanks
Sebastian

On Mar 30, 2:34 pm, Sebastian <[email protected]> wrote:
> Hi,
>
> I've tried many different options to get thephoneNumbersfrom the
> Local Search API, but I didn't manage to do so.
>
> I count how many numbers are in thephoneNumbersvariable and I get 1
> or 2 depending on the record,
>
> count($sr['phoneNumbers'][0])
>
> I followed the reference guidelines, to try to do different options
> but I don't manage to do so. The guide says there are 3 variables to
> thephoneNumbers:
>
>                 $search_results['results'][$i]['phoneNumbers'] = 
> $r->phoneNumbers;
>                 $search_results['results'][$i]['type'] = $r->type; // 1) main 
> 2) fax
> 3) mobile
>                 $search_results['results'][$i]['number'] = $r->number; // the 
> number
> itself
>
> I'd like to do so, in PHP using CURL.
>
> here are my tests:
>
> http://allmybookings.com/apilocal/search-results.php?q=restaurants+br...
>
> and here 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($_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>";}
> }
>
> ?>
>
> Has anyone manage to get this info?
>
> Thanks,
> Sebastian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to