用php解析rss,preg_match function“;编辑:str_replace";

用php解析rss,preg_match function“;编辑:str_replace";,php,parsing,rss,Php,Parsing,Rss,我正在用php解析这个rss,我正在尝试显示youtube视频。在第一个项目中,我收到一个错误,视频没有显示。在第二个项目中,视频正常显示。 我必须从此行中删除123.gr/: <iframe width="780" height="470" src="'http://123.gr///www.youtube.com/embed/WDK5BTuFMRM?rel=0&vq=hd1080" frameborder="0" allowfullscreen></iframe&

我正在用
php
解析
这个
rss
,我正在尝试显示youtube视频。在第一个
项目中,我收到一个错误,视频没有显示。在第二个
项目中,视频正常显示。
我必须从此行中删除
123.gr/

 <iframe width="780" height="470" src="'http://123.gr///www.youtube.com/embed/WDK5BTuFMRM?rel=0&vq=hd1080" frameborder="0" allowfullscreen></iframe>
下面是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);
$xml=file\u get\u contents($url);
preg_match_all(“[(?Pwww\.youtube\.com.*?”),$xml,$matches);
var_dump($matches);

这将在
$matches
中为您提供一个数组,其中包含指向rss xml中找到的youtube视频的所有链接。

最后,我使用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;     
        ?>


感谢您的回答benjamin,但我需要保留iframe元素,以了解其工作原理。深夜我将上传代码!
<?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;     
        ?>