2013-04-09 62 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));