note 38951 deleted from function.preg-replace-callback by nlopess

From: Date: Tue, 13 Jan 2004 14:44:12 +0000
Subject: note 38951 deleted from function.preg-replace-callback by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-63420@lists.php.net to get a copy of this message
Note Submitter: rickardsjoquist@hotmail.com ---- 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.

« previous php.notes (#63420) next »