Search code examples
phphtmlxmlapiflickr

Flickr api title


Hello everyone I am trying to make a gallery on my website and I am pulling the images/sets from flickr. I am able to load all the sets with this bit of code:

$flickr = simplexml_load_file('http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key='.$api.'&user_id='.$user_id.'');
foreach($flickr->photosets->photoset as $ps) {
      echo '<img src="http://farm'.$ps['farm'].'.staticflickr.com/'.$ps['server'].'/'.$ps['primary'].'_'.$ps['secret'].'_q.jpg"><br />';
}

With this it will return a list of all the set's main images. However I also would like to add the title above it but the XML output of the title is in $flickr->photosets->photoset->title making it hard for me to get the title above every picture. Is there a easy way to get the title inside the foreach loop for the images but that the title also aligns correctly with the image?

the xml flickr outputs looks like:

<photosets page="1" pages="1" perpage="30" total="2" cancreate="1">
  <photoset id="72157626216528324" primary="5504567858" secret="017804c585" server="5174" farm="6" photos="22" videos="0" count_views="137" count_comments="0" can_comment="1" date_create="1299514498" date_update="1300335009">
    <title>Avis Blanche</title>
    <description>My Grandma's Recipe File.</description>
  </photoset>
</photosets>

Solution

  • If it's with the given XML, you can obtain it inside of the foreach loop with $ps->title.