我正在尝试编写一个PHP脚本,解析https://feeds.transistor.fm/the-good-news-podcast上所有.mp3的XML文件,然后回显它们。我已经开始使用PHP的simplexml_load_file()了。 mp3的位置如下:
<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>";
}
}
?>
答案 0 :(得分:0)
感谢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>';
}
}
?>
答案 1 :(得分:0)
如果应用它,你可以尝试一些简单的事情。
$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
)
)