1

I am parsing an image json from flickr

$jsrc = "https://api.flickr.com/services/rest/?text=Web&format=json&nojsoncallback=1&extras=url_l%2Curl_o%2Curl_z%2Curl_m&page=1&sort=relevance&api_key=cae293081d7db65b538c8bd4e90c988a&method=flickr.photos.search&per_page=10";
$json = file_get_contents($jsrc);
$jset = json_decode($json, true);

once I parse it I can only see a raw data like print_r($jset);

I need to do something like

foreach($jset as $d) 
{ echo $d['owner'] ;}

I need to select a specific tag in this parsed Json Array list how I can do that ?

1
  • Could you post json_decode code to your question. Commented Mar 27, 2014 at 10:26

2 Answers 2

4

You can run through the array like this:

$jsrc = "https://api.flickr.com/services/rest/?text=Web&format=json&nojsoncallback=1&extras=url_l%2Curl_o%2Curl_z%2Curl_m&page=1&sort=relevance&api_key=cae293081d7db65b538c8bd4e90c988a&method=flickr.photos.search&per_page=10";
$json = file_get_contents($jsrc);
$jset = json_decode($json, true);

echo "<pre>";

foreach ($jset['photos']['photo'] as $photo) {
    //print_r($photo);
    echo $photo['owner'];
    echo "<hr />";
}
Sign up to request clarification or add additional context in comments.

2 Comments

okay this is good to understand what you get but I need to get only 'owner' inside $photo for example, how can I do that ?
@zyrag I have edited this answer.please see it. and accept answer.
0

You can use this loop:

foreach ($jset['photos']['photo'] as $photo) {
  echo '<p><img src="' . $photo['url_o'] . '" /><br />Owner: ' . $photo['owner'] . '</p>';
}

The above will display the image with the owner underneath. You can tweak this as you need.

To access individual items, like the owner and the URL, you can change the index inside $photo[''].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.