很好,我再次请求您的帮助,我有一个包含多首歌曲的xml文件(http://radiojoven.6te.net/AirPlayHistory.xml),我只想把“我需要您的爱”这首歌从“杂乱无章”中拿出来,但是我使用了我在这里找到的代码无法显示所有的歌曲。能帮我解决这个问题吗?
<?php
$xml = simplexml_load_file("http://radiojoven.6te.net/AirPlayHistory.xml");
foreach($xml->Song as $item)
echo $item->Artist['name'] . " - " . $item['title'] ."<br>";
?>
谢谢!
发布于 2016-05-22 11:03:10
我认为您正在寻找的是一个条件控制结构,即if (如果我是您已经知道的东西,我很抱歉)。所以在你的循环里你可以:
foreach($xml->Song as $item) {
if ($item->Artist['name'] == 'SHAGGY' && $item['title'] == 'I NEED YOUR LOVE') {
echo $item->Artist['name'] . " - " . $item['title'] ."<br>";
}
}(对不现实的例子表示遗憾,您可能会发现变量中的条件项会偏离轨道)。
还有其他方法可以查询和过滤特定于XML文档的内容,也就是可以使用的xpath。
https://stackoverflow.com/questions/37373321
复制相似问题