note 38951 added to function.preg-replace-callback
| From: | rickardsjoquist at hotmail dot com | Date: | Tue, 13 Jan 2004 08:46:29 +0000 |
| Subject: | note 38951 added to function.preg-replace-callback | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63395@lists.php.net to get a copy of this message | ||
How to use the global scope on a variable in a function called from preg_replace_callback:
$i=0;
function somefunction($m) {
global $i;
$i++;
return $m[0];
}
This will work:
$subject = preg_replace_callback('/(somepattern)/is', somefunction, $subject);
This won't:
$subject = preg_replace_callback('/(somepattern)/is', 'somefunction', $subject);
Solution: the function name should not be a string. Hope this helps someone as it sure had me
cursing a couple of times before I found out.
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38951
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38951&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38951&report=yes
Search -- http://master.php.net/manage/user-notes.php