2012-04-03 34 views
0

當前,這是我有的preg_replace字符串。用正則表達式中的另一個字符替換字符PHP

$mtg_post['post_content'] = preg_replace("[^\\x20-\\x7e]", "",$ability); 

這是$ ability中包含的數據示例。

At the beginning of your upkeep, put a doom counter on Armageddon Clock.£At the 
beginning of your draw step, Armageddon Clock deals damage equal to the number 
of doom counters on it to each player.£{4}: Remove a doom counter from Armageddon 
Clock. Any player may activate this ability but only during any upkeep step. 

我想用2xreturn或新段落來替換£字符嗎?在正則表達式,所以行看起來像這樣,但不太確定如何實現這一點。

At the beginning of your upkeep, put a doom counter on Armageddon Clock. 

At the beginning of your draw step, Armageddon Clock deals damage equal 
to the number of doom counters on it to each player. 

{4}: Remove a doom counter from Armageddon Clock. Any player may activate 
    this ability but only during any upkeep step. 

回答

3

無需這裏正則表達式,只需使用str_replace()

$out = str_replace("£", "\n\n", $in); 
+0

這將刪除已在他們£整個線。 – 2012-04-03 22:56:49

+0

不適合我,也不會有意義。這裏是一個演示:http://codepad.org/oho8zhgi – Cal 2012-04-03 23:02:21

+0

是的,我甚至手動把文本作爲變量,並刪除整條線。這裏是全碼的鏈接。 http://codepad.org/DupoYKzY – 2012-04-03 23:14:27