2
此选择括号内的字符串,提取文本不包含在括号
$text = 'ignore everything except this (text)';
preg_match('#\((.*?)\)#', $text, $match);
echo $match[1] . ' /parentheses';
我怎么能呼应,是不是括号内的文本?
此选择括号内的字符串,提取文本不包含在括号
$text = 'ignore everything except this (text)';
preg_match('#\((.*?)\)#', $text, $match);
echo $match[1] . ' /parentheses';
我怎么能呼应,是不是括号内的文本?
尝试以下操作:
$text = 'ignore everything except this (text)';
preg_match('/(.*)\((.*?)\)/', $text, $match);
echo "in parenthesis: " . $match[2] . "\n";
echo "outside parenthesis: " . $match[1] . "\n";
不用多说它假定一组括号。
尝试:
preg_match('^(*.?)\((*.?)\)(*.?)$', $text, $match);
echo $match[0] . $match[2];
假设只有一组括号。
整洁!谢谢!!! – woninana 2013-05-08 05:46:52