-1

i have this xml:

 -<lfm status="ok">
-<track>
<id>602366984</id>
<name>Barbarism Begins At Home (BBC TV Tube performance)</name>
<mbid/>
-<url>http://www.last.fm/music/The+Smiths/_/Barbarism+Begins+At+Home+(BBC+TV+Tube+performance)</url>
<duration>384000</duration>
<streamable fulltrack="0">0</streamable>
<listeners>10</listeners>
<playcount>24</playcount>
-<artist>
<name>The Smiths</name>
<mbid>40f5d9e4-2de7-4f2d-ad41-e31a9a9fea27</mbid>
<url>http://www.last.fm/music/The+Smiths</url>
</artist>
<toptags>
</toptags>
</track>
</lfm>

i want to fetch the name of track and artist, should i use 2 codes for this(next code) or is there a better way?

foreach ($xml -> track as $row) {
            $title = $row -> name;
            $artist = $row -> name;
            $duration = $row -> duration;

in this code iam getting, for the two, the name of artist.

  • $xml = simplexml_load_string($xml); //print_r($xml); foreach($xml->city as $val){ echo $val->name; } – Arun Jan 10 '15 at 11:36
  • Iam sorry @Arun, i dont understand, my xml is: $xml = simplexml_load_string($data); – Handsome_devil Jan 10 '15 at 11:42
  • Please do not duplicate your own question. If you need to add, consider what had been asked wrong. In any case edit and improve the [original question](http://stackoverflow.com/q/27870714/367456) – hakre Apr 03 '15 at 10:10

1 Answers1

1
foreach ($xml -> track as $row) {
            $title = $row -> name;
            $artist = $row ->artist-> name;
            $duration = $row -> duration;
Alex
  • 16,739
  • 1
  • 28
  • 51