Sleeper Posted April 3, 2012 Share Posted April 3, 2012 Hello. I'm trying to pull information out of an xml file. However I'm a bit lost in getting the actual value. $url="http://ws.audioscrobbler.com/2.0/?method=artist.getimages&artist=Dr%20Feelgood&limit=1&autocorrect=1&api_key=c107c9b5c09cb5693b6c19409dd984c1"; $xml = simpleXML_load_file($url,"SimpleXMLElement",LIBXML_NOCDATA); $largesquare=$xml->images->sizes->size[2]; Is what I have but its not pulling the information. The above url will give you the link to a set xml file for this example. And I want to get the info for the <size name="largesquare" width="126" height="126">http://userserve-ak.last.fm/serve/126s/43173899.jpg</size> I'm sure I'm doing something wrong that's a simple fix but I am lost here. In the sizes there are 6 different size options each with different names and I have no idea how to pull the one with the correct name that I need. Thank you to who ever can help me sort this out. Quote Link to comment https://forums.phpfreaks.com/topic/260282-php-and-xml-question/ Share on other sites More sharing options...
jayjay159357 Posted April 3, 2012 Share Posted April 3, 2012 Well if it was me id do <?php $url = 'url_of_xml_file'; $xml = simpleXML_load_file($url); //if you want to get multiple xml elements use a foreach loop... foreach($xml->element_name as $value) { echo $value; } //if you only want the first element do... echo $xml->element_name; ?> Quote Link to comment https://forums.phpfreaks.com/topic/260282-php-and-xml-question/#findComment-1334087 Share on other sites More sharing options...
Sleeper Posted April 3, 2012 Author Share Posted April 3, 2012 I guess I don't see your coding working so I'm not doing something right or I'm not explaining correctly. I just want the value for size name="largesquare" You can copy and paist the url to see the actual xml file so you can see how there are many different size option and I want the one that is named largesquare and I don't know how to pull just that info. Quote Link to comment https://forums.phpfreaks.com/topic/260282-php-and-xml-question/#findComment-1334091 Share on other sites More sharing options...
jayjay159357 Posted April 3, 2012 Share Posted April 3, 2012 if you want the value inside the element use <?php $url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getimages&artist=Dr%20Feelgood&limit=1&autocorrect=1&api_key=c107c9b5c09cb5693b6c19409dd984c1'; $xml = simplexml_load_file($url); echo $xml->images->image->sizes->size[2]; ?> I think this is what you want. I think it didnt work for you bacause you missed out image after images when getting the data. took me ages to code this for you haha. I think the xml is considerd "Messy". Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/260282-php-and-xml-question/#findComment-1334114 Share on other sites More sharing options...
Sleeper Posted April 3, 2012 Author Share Posted April 3, 2012 Well now I feel rather stupid..lol. I had that coding but I missed the image just went from images->sizes. Guess I'm just blind today. Makes since as to why it didn't work now when I expected it to..lol Thank You. Quote Link to comment https://forums.phpfreaks.com/topic/260282-php-and-xml-question/#findComment-1334173 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.