bravo14 Posted October 20, 2013 Share Posted October 20, 2013 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 6The parameters I need are within the photoset tag and not tags on their own. Any help would be great Quote Link to comment https://forums.phpfreaks.com/topic/283129-create-flickr-url-from-simplexml/ Share on other sites More sharing options...
codebyren Posted October 21, 2013 Share Posted October 21, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/283129-create-flickr-url-from-simplexml/#findComment-1454709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.