Hi Jeremy, I tried it, and I don¹t understand why but this: $sr['phoneNumbers'][0] stops the code in this point. See example below.
The funny thing is that $sr['addressLines'][0] works perfectly. So, I also tried $sr['phonenumbers'][0] (in lowercase, just in case). And in lowercase it doesn¹t stop the code, but it doesn¹t work neither. He is the web: http://allmybookings.com/googlelocalsearch.php?q=comocomo+brussels And here is the code: <?php require_once 'JSON.php'; # Your site URL $site = 'google.com'; # Make sure a search-query was entered if(isset($_GET['q']) || isset($_GET['categoryInput'])) { # Are we on the first page? $start = isset($_GET['start']) ? $_GET['start'] : 0; # The URL to the Google search API $url = 'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=' .urlencode($_GET['q']) .'&rsz=large&start=' .$start; # Initiate CURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, 'http://' .$site); $body = curl_exec($ch); curl_close($ch); # Decode the JSON returned (you need the JSON-class if json_decode is undefined) $body = json_decode($body); # Build array $i = 0; $search_results = array(); # Loop through all results foreach($body->responseData->results as $r) { $search_results['results'][$i]['title'] = $r->title; $search_results['results'][$i]['url'] = $r->url; $search_results['results'][$i]['content'] = $r->content; $search_results['results'][$i]['GsearchResultClass'] = $r->GsearchResultClass; $search_results['results'][$i]['viewportmode'] = $r->viewportmode; $search_results['results'][$i]['listingType'] = $r->listingType; $search_results['results'][$i]['lat'] = $r->lat; $search_results['results'][$i]['lng'] = $r->lng; $search_results['results'][$i]['accuracy'] = $r->accuracy; $search_results['results'][$i]['titleNoFormatting'] = $r->titleNoFormatting; $search_results['results'][$i]['ddUrl'] = $r->ddUrl; $search_results['results'][$i]['ddUrlToHere'] = $r->ddUrlToHere; $search_results['results'][$i]['ddUrlFromHere'] = $r->ddUrlFromHere; $search_results['results'][$i]['streetAddress'] = $r->streetAddress; $search_results['results'][$i]['city'] = $r->city; $search_results['results'][$i]['region'] = $r->region; $search_results['results'][$i]['country'] = $r->country; $search_results['results'][$i]['phoneNumbers'] = $r->phoneNumbers; $search_results['results'][$i]['type'] = $r->type; $search_results['results'][$i]['number'] = $r->number; $search_results['results'][$i]['addressLines'] = $r->addressLines; $i++; } # Loop through all the pages of results if(isset($body->responseData->cursor->pages)) { foreach($body->responseData->cursor->pages as $p) { $search_results['pages'][] = $p->start; } } # Make sure some results were returned if(isset($search_results['results'])) { ?> <?php foreach($search_results['results'] as $sr) { ?> <b><a href="<?php echo $sr['url']; ?>" target="_blank"><?php echo $sr['titleNoFormatting']; ?></a><br /></b> <?php if ($sr['addressLines']) { echo $sr['addressLines'][0]."<- address 1<br>"; } ?> <?php if ($sr['addressLines']) { echo $sr['addressLines'][1]."<- address 2<br>"; } ?> <?php echo "count phoneNumbers with [0]: ". count($sr['phoneNumbers'][0])."<br>"; ?> <?php echo "count phoneNumbers without [0]: ". count($sr['phoneNumbers'])."<br>"; ?> <?php echo "phoneNumbers without [0]: ". $sr['phoneNumbers']." gives an array<br>"; ?> <?php echo "phoneNumbers with [0] gives the problem & stops the code: ". $sr['phoneNumbers'][0]; ?> <?php // if ($sr['phoneNumbers']) { echo "phone Numbers: ".$sr['phoneNumbers'][main][number][1]."<br>"; } ?> <?php // if ($sr['type']) { echo count($sr['type'])."<br>"; } ?> <?php // if ($sr['number']) { echo $sr['number']."<br>"; } ?> <div style="margin-bottom:6px;"></div> <? } } else { ?> <h1><p><strong>Sorry, there were no results</strong></p></h1> <?php } } End of code On 23/03/09 11:36, "Jeremy Geerdes" <[email protected]> wrote: > $sr['phoneNumbers'][0] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
