2014-02-07 31 views
1

從文本中的特殊字符我有一個​​字符串如何刪除使用PHP和正則表達式

$k="My name is Alice[1]"; 

我想是刪除從我的字符串使用最基本的步驟,「[1]」這樣的句子會像

$k="My name is Alice"; 

所以應該刪除內部[]中的所有內容。

+3

那你試試這麼遠嗎? – Reeno

+0

沒有:-(不能得到它 – Confused

+0

http://codepad.viper-7.com/tW2cRE – Prasanth

回答

1

使用此:

$text = preg_replace('/\[[0-9]+\]/','',$text); 
+0

感謝它工作 – Confused

+0

如果它的工作,請接受答案 – Reeno

0

這樣做:

$k="My name is Alice[1]"; 
$k = preg_replace('/\[[0-9]+\]/','',$k);