PHP: Best way to extract text within parenthesis?

后端 未结 8 1464
北海茫月
北海茫月 2020-11-28 06:11

What\'s the best/most efficient way to extract text set between parenthesis? Say I wanted to get the string \"text\" from the string \"ignore everything except this (text)\"

8条回答
  •  遥遥无期
    2020-11-28 06:31

    Use a regular expression:

    if( preg_match( '!\(([^\)]+)\)!', $text, $match ) )
        $text = $match[1];
    

提交回复
热议问题