我正在尝试编写一个PHP脚本,解析所有.mp3文件的https://feeds.transistor.fm/the-good-news-podcast的XML文件,然后回显它们。我已经开始使用PHP的simplexml_load_file()。 mp3的位置如下所示:PHP为所有.mp3链接解析XML文件
<enclosure url="https://media.transistor.fm/025fe5da.mp3" length="3636030" type="audio/mpeg"/>
我该如何定位所有机箱标签网址?以下是我有这么远,但它不工作:
<?php
$mysongs = simplexml_load_file('https://feeds.transistor.fm/the-good-news-podcast');
foreach ($mysongs as $songinfo):
$title=$songinfo->enclosure(url);
echo $title;
endforeach;
?>
也试过,但没有运气:
<?php
$html= simplexml_load_file('https://feeds.transistor.fm/the-good-news-podcast');
$dom = new DOMDocument;
$dom->loadXML($html);
foreach ($dom->getElementsByTagName('enclosure') as $tag) {
if(strpos($tag->getAttribute('url'),'.mp3')!==false)
{
echo $tag->getAttribute('url')."<br>";
}
}
?>