PHP: Best way to extract text within parenthesis?

i’d just do a regex and get it over with. unless you are doing enough iterations that it becomes a huge performance issue, it’s just easier to code (and understand when you look back on it)

$text="ignore everything except this (text)";
preg_match('#\((.*?)\)#', $text, $match);
print $match[1];

Leave a Comment