Jump to content
bravo14

Create flickr url from simplexml

Recommended Posts

I am trying to create a flickr url using the XML file from the site

 

the code I am using is as follows

 

 
<?php
$file="http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=7952c4f1e6dfd2ae1420aec860616f6e&user_id=93306691%40N08&format=rest&auth_token=72157636755071086-2072507680111a83&api_sig=8032afd164bff4d17c4574ae246ce92b";
$sets=simplexml_load_file($file);
 
foreach($sets->xpath('//photoset') as $set){
echo '<a><li><img src="http://farm'.$set{farm-id}.'.staticflickr.com/'.$set{server-id}.'/'.$set{id}.'_'.$set{secret}.'.jpg"/><h3>'.$set->title.'</h3></li></a>';
}
//print_r($sets);
?>

 

The XML is laid out as below

 

<photosets cancreate="1" page="1" pages="1" perpage="13" total="13">
    <photoset id="72157634817057978" primary="9378217918" secret="66a440b8e3" server="3753" farm="4" photos="28" videos="0" needs_interstitial="0" visibility_can_see_set="1" count_views="34" count_comments="0" can_comment="1" date_create="1374935118" date_update="1374954932">
        <title>Coventry v Birmingham - 26-07-13</title>
        <description>Photos of the occasion when the Birmingham Brummies ascended to the top of the Elite League table.</description>
    </photoset>
</photosets>

 

But I am getting the following error displayed

 

  • Notice: Use of undefined constant farm - assumed 'farm' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant id - assumed 'id' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant server - assumed 'server' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant id - assumed 'id' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant id - assumed 'id' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6 Notice: Use of undefined constant secret - assumed 'secret' in /home/sites/birminghambrummies.co/public_html/library/flickr_sets.php on line 6

The parameters I need are within the photoset tag and not tags on their own.

 

Any help would be great

Share this post


Link to post
Share on other sites

Firstly, you are trying to access an attribute called "farm" as "farm-id" and "server" as "server-id".  You probably want :

$set['farm']

and not:

$set{farm-id}

Likewise with server vs server-id.

 

Then, note the presence of the quotes wrapping 'farm-id' which stops PHP from treating "farm" and "id" as separate constants - which is what caused your "Use of undefined constant XYZ" errors.

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.