Jump to content

How to use a foreach statement to loop through json search engine results?


the5thace

Recommended Posts

Sample query: http://www.faroo.com/api?q=elephants&start=1&length=10&l=en&src=web&f=json&jsoncallback=mycallback

 

I do not quite understand the parameters I need to use for a foreach statement to work on this query. 

 

Previously I have managed the foreach to loop through Blekko results sets with

 
 
foreach ($js->RESULT as $item)
         {  if(@$item->snippet || @$item->url_title)
         {$Blekko[$i] = "<a href=\"{$item->url}\"> 
         {$item->url_title}</a>blekko     
          <p>$item->snippet}</p>"; 

 

 but I'm not sure how it actually works. Bing query : https://api.datamarket.azure.com/Bing/Search/Web?$format=json&Query=%27bing%27

Edited by the5thace
Link to comment
Share on other sites

I understand that but how do you know which variable offers the array of results? 

My current foreach does not work for the faroo query. Giving me an error on the foreach line.

foreach ($js->results as $item)
        {
            $Faroo[$i] = "<a href=\"{$item->url}\"> 
            {$item->title}</a>faroo  
            <p>$item->kwic}</p>";    
            $i++;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.