我想設置一個正則表達式來檢測[quote] ??? [/ quote]並將其刪除。通過RegEx去掉BBCode
這是我有,但它是不工作:
$post['body'] = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $post['body']);
任何人都可以點我在正確的方向?
我還想在[quote] ??? [/ quote]之前或之後刪除任何線路制動器。
我想設置一個正則表達式來檢測[quote] ??? [/ quote]並將其刪除。通過RegEx去掉BBCode
這是我有,但它是不工作:
$post['body'] = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $post['body']);
任何人都可以點我在正確的方向?
我還想在[quote] ??? [/ quote]之前或之後刪除任何線路制動器。
只是想出了我自己的問題。
$post['body'] = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $post['body']);
$body = trim(rtrim($post[0]['body']));
trim()將刪除字符串兩邊的空格。所以不需要添加另一個rtrim。 – reggie 2012-11-07 20:57:57
這裏是我測試用腳本:
$text = "I am trying to setup a regex that will detect [quote]???[/quote] and will remove it.\r\nThis is what I have but it is not working:";
$sentences = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $text);
echo '<pre>'.print_r($sentences, true).'</pre>';
而且我的輸出:
I am trying to setup a regex that will detect and will remove it.
This is what I have but it is not working:
你可以看到:[報價] ??? [/報價]被刪除。
我認爲你的問題在其他地方。檢查$ post ['body']的值!
也許這是一個拼寫錯誤,你meen $ _POST ['body']?
就想通了:'$信息[ '身體'] =的preg_replace( 「/?\ [報價\](+)\ [\ /報價\] /是」,「 ',$ post ['body']); $ body = trim(rtrim($ post [0] ['body']));' – ATLChris 2011-04-22 19:36:01