PHP: Best way to extract text within parenthesis?

后端 未结 8 1466
北海茫月
北海茫月 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:32

    i think this is the fastest way to get the words between the first parenthesis in a string.

    $string = 'ignore everything except this (text)';
    $string = explode(')', (explode('(', $string)[1]))[0];
    echo $string;
    

提交回复
热议问题