PHP带字符串 $var=”单击此按钮。(去了天堂)(然后去了别的地方);

PHP带字符串 $var=”单击此按钮。(去了天堂)(然后去了别的地方);,php,string,Php,String,如何获取放在第一个括号之间的文本 将其值抛出到$extra 在本例中,$extra='goes to Hearth' 谢谢 $var = 'Click on this <a href="#">link</a>. (goes to heaven) (and then somewhere else)'; 对于您提供的示例,这是严格正确的。如果要解析任意HTML,则必须使用或类似的格式 preg_match("/\\((.+?)\\)/", $var, $matches);

如何获取放在第一个括号之间的文本

将其值抛出到
$extra

在本例中,
$extra='goes to Hearth'

谢谢

$var = 'Click on this <a href="#">link</a>. (goes to heaven) (and then somewhere else)';
对于您提供的示例,这是严格正确的。如果要解析任意HTML,则必须使用或类似的格式

preg_match("/\\((.+?)\\)/", $var, $matches);
$extra = $matches[1];