我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>
任何帮助将不胜感激
答案 0 :(得分:0)
你可以使用这样的东西获取所有youtube链接:
$xml = file_get_contents($url);
preg_match_all('[(?P<link>www\.youtube\.com.*?)"]', $xml, $matches);
var_dump($matches);
这将为您提供$matches
中的数组,其中包含您在rss xml中找到的YouTube视频的所有链接。
答案 1 :(得分:0)
最后我使用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;
?>