Below is my code:
foreach(simplexml_load_file('http://www.bbc.co.uk/radio1/playlist.xml')->item as $link){
$linked = $link->artist;
$xml_data = file_get_contents('http://ws.audioscrobbler.com/2.0/?method=artist.getimages&artist=' . $linked . '&api_key=b25b959554ed76058ac220b7b2e0a026');
$xml = new SimpleXMLElement($xml_data);
foreach($xml->images as $test){
$new = $test->image->sizes->size[4];
echo "<img src='$new'>";
?><br /><?php
}}
?>
This does work, but it only displays one record from many, it shows the first record from the XML file. I want it to display all of the records.
What I am trying to achieve from this code is:
I have an xml file I am getting the artist name from, im then listing all of the artist names and inserting them into a link which is therefore dynamically created from them generated artist names. I then want to take the dynamically created link, which is another xml file and parse that file to get the size node which is an image link (the image is of the artist). I then want to echo that image link out into an image tag which displays the image.
It partially works, but as I said earlier, It only displays one record instead of all the records in the xml file.
The returned XML is structured like this:
Which means you have to iterate
Example:
On a sidenote, there is no reason to use
file_get_contentsthere. Either usesimplexml_load_fileor usenew SimpleXmlElement('http://…', false, true). And really no offense, but given that I have already given you an almost identical solution in the comments to When extracting artist name from XML file only 1 record shows I strongly suggest you try to understand what is happening there instead of just copy and pasting.