note 20457 deleted from function.preg-replace-callback by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 12:27:13 +0000 |
| Subject: | note 20457 deleted from function.preg-replace-callback by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57458@lists.php.net to get a copy of this message | ||
Note Submitter: me@garyshi.net
----
how to pass the callback function more parameters than just match parts? now i can only use an ugly
global variable.
suppose the replacement of the regular expression depends on the context environment. e.g.,
while (list($k,$v) = each($config)) {
while (list($k2,$v2) = each($config[$k])) {
$_eval_sub_context = $config[$k];
$config[$k][$k2] = preg_replace_callback($pattern, "eval_sub", $config[$k][$k2]);
}
}
function eval_sub($match) {
global $_eval_sub_context;
return <some calculation based on both $_eval_sub_context and $match>;
}