PHP 4.0 Bug #3657: ereg_replace behavior changed from php3.
| From: | joakim at erdfelt dot net | Date: | Mon, 28 Feb 2000 21:43:39 +0000 |
| Subject: | PHP 4.0 Bug #3657: ereg_replace behavior changed from php3. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-16103@lists.php.net to get a copy of this message | ||
From: joakim@erdfelt.net
Operating system: win32
PHP version: 4.0 Beta 4 Patch Level 1
PHP Bug Type: Misbehaving function
Bug description: ereg_replace behavior changed from php3.
Experienced some difficulty when moving from php3 to php4 and using the class.FastTemplate.php3
(from www.thewebmasters.net).
I traced the offending code down to how ereg_replace works.
The following example of various uses of the ereg_replace should produce the string "This is a
replaced String"
each and every time. (which it does do under php3, but not php4) Since I couldn't find any doc
stating that the behaviour was intentionally changed, I'm assuming that this is a legitimate
bug.
it seems to stem from the use of "{$key}" in the $pattern.
/* the code example (short) */
$key = "TEST";
$str = "This is a {TEST} String";
echo ereg_replace("{$key}", "replace", $str);
/* produces "This is a {replaced} String" */
/* Example php code (longer) ------------ */
$string = "This is a {TEST} String";
$key = "TEST";
$srch1 = "{$key}";
$srch2 = "{" . $key . "}";
echo ereg_replace( "{TEST}", "replaced", $string ) . "\n";
echo ereg_replace( "{$key}", "replaced", $string ) . "\n";
echo ereg_replace( "{" . $key . "}", "replaced", $string ) .
"\n";
echo ereg_replace( $srch1, "replaced", $string ) . "\n";
echo ereg_replace( $srch2, "replaced", $string ) . "\n";
echo ereg_replace( "(\{[A-Z0-9_]+\})", "replaced", $string ) . "\n";
echo ereg_replace( "{([A-Z0-9_]+)}", "replaced", $string ) . "\n";
/* ----------- end of example code. */