2014-04-20 52 views
0

parsing這個rssphp,我試圖顯示在YouTube video.In第一item我得到一個錯誤,並且不顯示視頻。在第二個item視頻正常顯示。
我必須從該行刪除123.gr//解析RSS使用PHP,功能的preg_match「編輯:str_replace函數」

<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

Finnally我使用str_replace函數,並同時顯示videos.Here的是我的代碼,也許會幫助別人,將來

<?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;  
     ?> 
0

你可以使用這樣的事情讓所有的樣本youtube鏈接:

$xml = file_get_contents($url); 
preg_match_all('[(?P<link>www\.youtube\.com.*?)"]', $xml, $matches); 
var_dump($matches); 

這會給你一個$matches的數組,其中包含你的rss xml中找到的youtube視頻的所有鏈接。

+0

謝謝您的回答本傑明,但我需要保持iframe元素​​ – marYOs

+0

實際上我希望以src開始:src =「http://youtube.com/ .. ...「 – marYOs

+0

瞭解它是如何工作的。晚上我會上傳代碼! – marYOs