i need something like that:
function highlight_code($str) {
$search = array(
'/regexp1/i',
'/regexp2/i',
'/regexp3/i'
);
// Array of PHP 5.3 Closures
$replace = array(
myFunction1($matches),
myFunction2($matches),
myFunction3($matches)
);
// preg_replace_callback does not support array replacements.
foreach ($search as $key => $regex) {
$str = preg_replace_callback($search[$key], $replace[$key], $str);
}
return $str;
}
but running preg_replace_callback only 1 time since my $str is a large document and can be slow way looping this many times.
i cannot use preg_replace since i need to pass what has been matched by patterns to a function that must be process it.
i've read this article that seems to be a solution: preg_replace with multiple patterns replacements at once
but i didn't understand very well how grouping works and how can i use it.. moreover i would keep the array way instead long regexp string ( if they do not change performances ) since they are more clear.
could you help me? thanks in advance
/e
flag for instead of the anonymous functions? Looking at your input it would have crazy bad security though. – complex857 Apr 5 at 20:52/e
: This feature has been DEPRECATED as of PHP 5.5.0. Relying on this feature is highly discouraged. – nickb Apr 5 at 20:55(?R)
. – Wrikken Apr 5 at 21:41