PHP为所有.mp3链接解析XML文件
我正在尝试编写一个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>";
}
}
?>
回答:
就想通了感谢Get enclosure img url from rss feed:
<?php $rss=simplexml_load_file('https://feeds.transistor.fm/the-good-news-podcast');
foreach ($rss->channel->item as $item) {
if (isset($item->enclosure)) {
echo $item->enclosure['url'].'<br>';
}
}
?>
回答:
你可以尝试一些简单的东西,如果这是它的应用。
$html= simplexml_load_file('https://feeds.transistor.fm/the-good-news-podcast'); preg_match_all("/h.*mp3/", $html, $mp3s);
foreach ($mp3s as $mp3){
echo $mp3.'<br>';
}
这将输出
array(1 0 => array(9
0 => https://media.transistor.fm/0cf8f8b1.mp3
1 => https://media.transistor.fm/f45a0d7d.mp3
2 => https://media.transistor.fm/2ba746c9.mp3
3 => https://media.transistor.fm/025fe5da.mp3
4 => https://media.transistor.fm/58cf9a08.mp3
5 => https://media.transistor.fm/65a6df2b.mp3
6 => https://media.transistor.fm/33e65d6c.mp3
7 => https://media.transistor.fm/e29ea8d3.mp3
8 => https://media.transistor.fm/3422d3aa.mp3
)
)
以上是 PHP为所有.mp3链接解析XML文件 的全部内容, 来源链接: utcz.com/qa/260316.html