Reputation: 87
Good, again I ask your help, I have a xml file (http://radiojoven.6te.net/AirPlayHistory.xml) with several songs and I just wanted to take the song "I Need Your Love" from "SHAGGY "but I using a code I found here can not, appears all the songs. Could help me solve the problem?
<?php
$xml = simplexml_load_file("http://radiojoven.6te.net/AirPlayHistory.xml");
foreach($xml->Song as $item)
echo $item->Artist['name'] . " - " . $item['title'] ."<br>";
?>
Thanks!
Upvotes: 0
Views: 39
Reputation: 20753
I think what you are looking for a conditional control structures, namely if
(I'm sorry if I'm something you already know). So inside your loop you can go:
foreach($xml->Song as $item) {
if ($item->Artist['name'] == 'SHAGGY' && $item['title'] == 'I NEED YOUR LOVE') {
echo $item->Artist['name'] . " - " . $item['title'] ."<br>";
}
}
(Sorry for the unrealistic example, you probably get the derails for the conditionals in variables).
There are other ways to query and filter things specific to XML documents, namely xpath that use can use as well.
Upvotes: 1