Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6239153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:20:36+00:00 2026-05-24T11:20:36+00:00

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=’ .

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:20:36+00:00Added an answer on May 24, 2026 at 11:20 am

    The returned XML is structured like this:

    <lfm>
        <images>
            <image>
            <image>
            …
            <image>
    

    Which means you have to iterate

    $xml->images->image
    

    Example:

    $lfm = simplexml_load_file('http://…');
    foreach ($lfm->images->image as $image) {
        echo $image->sizes->size[4];
    }
    

    On a sidenote, there is no reason to use file_get_contents there. Either use simplexml_load_file or use new 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below code : URL oracle = new URL(http://www.oracle.com/); URLConnection inputStream =oracle.openConnection(); InputStream in =
I had an access to modified closure error in the code below foreach (var
The below code give me a foreach error. What appears to be the issue
The below code is not working <c:forEach var=row varStatus=rowCount begin=1 end=10> <c:set var=entry scope=request
Can someone confirm that the below code definitely removes items from the BlockingCollection foreach
I have a doubt in php foreach iteration. Please look my below code. CODE
I have the code below to create a XML file <?php try { $dom
Below is my code: foreach my $node (@switch_list) { chomp $node; print $node \n;
With the code below I import my XML file to mySQL with the limitation
I have some php code below, where I'm using foreach. <div class=carousel-inner> <?php if(count($items)):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.