我正在嘗試編寫一個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>";
}
}
?>