2013-04-09 61 views
-1
擺脫文本的

說你有一個像這樣的字符串:獲得()之間在PHP

This is a string (with parenthesis stuff)

你會如何改變,要

This is a string

回答

2

替換:

preg_replace('/\(.*?\)/', '', $str); 
+0

+1這個... :) – 2013-04-09 05:01:51

1

使用正則表達式。

用空字符串替換\([^)]*\)

注意:如果有多對括號,這將取代最內層的一個。

1

試試這個

$string = "This is a string (with parenthesis stuff)"; 
    echo preg_replace("/\([^)]+\)/","",$string); // 'ABC ' 

,或者你可以做到這一點也

$str = "This is a string (with parenthesis stuff)"; 
    $str = trim(preg_replace('/\s*\([^)]*\)/', '', $str));