Bug #16040 Updated: nested preg_replace_callback()'s won't work
| From: | jimw@php.net | Date: | Tue, 09 Apr 2002 21:00:01 +0000 |
| Subject: | Bug #16040 Updated: nested preg_replace_callback()'s won't work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-4477@lists.php.net to get a copy of this message | ||
ID: 16040
Updated by: jimw@php.net
Reported By: markus.pfefferle@web.de
-Status: Open
+Status: Feedback
Bug Type: PCRE related
Operating System: Linux
PHP Version: 4.1.1
New Comment:
the code below works fine for me. please provide a complete example of
code that fails.
function funcB($arr) {
return 'whatever';
}
function funcA($arr) {
$someotherhaystack = '%value1% foo %value2%';
$t = preg_replace_callback("/%value([0-9]+)%/", "funcB",
$someotherhaystack);
return $t; // $t still makes sense here
}
$haystack = '%text12% bar %text13%';
echo preg_replace_callback("/%text([0-9]+)%/", "funcA", $haystack);
Previous Comments:
------------------------------------------------------------------------
[2002-03-13 07:31:50] markus.pfefferle@web.de
A preg_replace_callback() that calls a callback function which in turn
makes use of a preg_replace_callback() function too, will not work
correctly. The first preg_replace_callback() will substitute gibberisch
even though the callback function returned a valid string.
Example:
function funcB($arr)
{
...
return $whatever;
}
function funcA($arr)
{
...
$t = preg_replace_callback("/%value([0-9]+)%/", "funcB",
$someotherhaystack)
return $t; // $t still makes sense here
}
echo preg_replace_callback("/%text([0-9]+)%/", "funcA", $haystack);
// but whatever funcA returned, just some gibberisch is substituted for
/%text[0-9]+%/
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=16040&edit=1