2011-09-09 42 views
0

可能重複:
RegEx match open tags except XHTML self-contained tagsPHP預浸更換工作不

您好首先我想說我是個初學者。

我的問題是我正在開發一個視頻網站,該網站從其他網站拉出一個XML,並將數據保存在我的數據庫中。

在嵌入增加了一個:

<div style="margin:auto" align="center">- 
embed here 
</div> 

,並用文本的阿克爾在這裏上傳免費視頻。

現在我想刪除這些與preg替換,但它不工作。

function insertvids() { 

     $url = "http://thesite/rss.xml"; 
     $data = simplexml_load_file($url, "SimpleXMLElement", LIBXML_NOCDATA); 
     //print_r($data->channel->item); 

     foreach ($data->channel->item as $r) 
     { 
      $title = $r->title; 
      $description = $r->description; 
      $embed = $r->embed; 
      $thumb = $r->image; 
      $duration = $r->duration; 

      $string = $r->embed; 

      $replace = array(); 
      $replace[0] = '-<div style="margin:auto" align="center">-'; 
      $replace[1] = '-<a href="http://thesite.com" target="_blank">-'; 
      $replace[3] = '-Unlimited video upload for free.-'; 
      $replace[4] = '-</a></div>-'; 
      $replaceto = array(); 
      $replaceto[0] = ' '; 
      $replaceto[1] = ' '; 
      $replaceto[2] = ' '; 
      $replaceto[3] = ' '; 
      $replaceto[4] = ' '; 


      preg_replace($replace, $replaceto, $string); 

      $data = array(
       'title' => ''.$title.'', 
       'description' => ''.$description.'', 
       'thumbnail' => ''.$thumb.'', 
       'embed' => ''.$embed.'', 
       'duration' => ''.$duration.'', 
       'type' => 'slutload' 
     ); 
      $this->db->insert('videos', $data); 
      //print_r($data) . "<br>"; 
     } 

    } 

正試圖找出我失蹤的東西。如果我運行腳本,它什麼都不做,如果我改變 - 它給我和錯誤,它是無效的。

難道有人請指出我做錯了什麼嗎?

+0

如果它添加了一個固定的標記,爲什麼你需要正則表達式來刪除它?此外,當您收到錯誤消息時,請不要提供它們的模糊描述:請改爲複製文字消息。 –

+1

爲什麼不使用HTML解析器? – ThiefMaster

+0

thnaks爲大拇指下來:)保持它... :) – Side

回答

2

Preg_replace不修改參數。它只會返回一個數組或一個字符串(根據參數的類型)。

+0

感謝您所瞭解的信息 – Side

+0

它解決了您的問題嗎? – Raveline