note 20457 added to function.preg-replace-callback
| From: | me at garyshi dot net | Date: | Thu, 04 Apr 2002 10:02:51 +0000 |
| Subject: | note 20457 added to function.preg-replace-callback | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28598@lists.php.net to get a copy of this message | ||
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>;
}
--
http://www.php.net/manual/en/function.preg-replace-callback.php
http://master.php.net/manage/user-notes.php?action=edit+20457
http://master.php.net/manage/user-notes.php?action=delete+20457
http://master.php.net/manage/user-notes.php?action=reject+20457