我是parsing
,这个rss
和php
,我正在尝试显示youtube视频。在第一个item
中,我得到了一个错误,视频没有显示。在第二item
中,视频被正常显示
我必须从此行中删除123.gr//
:
<iframe width="780" height="470" src="'http://123.gr///www.youtube.com/embed/WDK5BTuFMRM?rel=0&vq=hd1080" frameborder="0" allowfullscreen></iframe>
我认为这样做的一个好主意是使用explode function
,但我还没有找到方法。
看看我的代码:
<?php
$html = "";
$url = "123.xml";
$xml = simplexml_load_file($url);
for ( $i = 0; $i < 10; $i++ ){
$title = $xml->channel->item[$i]->title;
$description = $xml->channel->item[$i]->description;
print_r(explode('"',$description,5));
?>
<div data-role="content">
<div data-role="collapsible" data-theme="b">
<h3><?php echo $title ?></h3>
<p><?php echo $description ?></p>
</div>
</div>
<?php
}
?>
这是rss 的一个示例
<item>
<title>This is the title</title>
<description>
<![CDATA[Some text
<p>
<div align="center">
<iframe width="780" height="470" src="'http://123.gr///www.youtube.com/embed/WDK5BTuFMRM?rel=0&vq=hd1080" frameborder="0" allowfullscreen></iframe>
</div>
]]>
</description>
</item>
<item>
<title>This is the title</title>
<description>
<![CDATA[Some text
<p>
<div align="center">
<iframe width="780" height="470" src="'http://www.youtube.com/embed/WDK5BTuFMRM?rel=0&vq=hd1080" frameborder="0" allowfullscreen></iframe>
</div>
]]>
</description>
</item>
如有任何帮助,将不胜感激
你可以用这样的东西来获取所有youtube链接:
$xml = file_get_contents($url);
preg_match_all('[(?P<link>www'.youtube'.com.*?)"]', $xml, $matches);
var_dump($matches);
这将在$matches
中为您提供一个数组,其中包含rss.xml中找到的youtube视频的所有链接。
Finally我使用str_replace并显示两个视频。这是我的代码,也许会在未来帮助
<?php
$html = "";
$url = "http://123.gr/index.php?format=feed&type=rss";
$xml = file_get_contents($url);
$x = new SimpleXmlElement($xml);
foreach ( $x->channel->item as $entry ){
$part_to_replace = array("http://123.gr///www.youtube.com/");
$replaced = array("http://www.youtube.com/");
$entry->description = str_replace( $part_to_replace, $replaced, $entry->description );
echo $entry->description;
echo $entry->title;
?>