I attempted the following code:
$for_callback=create_function('$match','return $GLOBALS[\'replacements\'][$match[1]];');
$result = preg_replace_callback( $regex, '$for_callback', $string);
The variable $GLOBALS['replacements']
is generated dynamically before this function is called.
I get an error message like
Warning: preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, '$for_callback', to be a valid callback in...
created functions and callbacks are both new to me. This is growing out of some code given to me by nickb at My question about preg_replace that turned into preg_replace_callback
.
What I'm trying to do is wrap the code in that answer into a function and I'm running into errors with scope avoiding re-defining a function. (upgrading to PHP 5.3+ is a remote posibility option for me at the moment.)
How do I get this to work?