From:             [EMAIL PROTECTED]
Operating system: windows 2000 SP1
PHP version:      4.0.4
PHP Bug Type:     Regexps related
Bug description:  preg_replace with e modifier barfs on quotes

I'm running PHP version 4.04, Windows NT 5.0 build 2195.

Using the "e" modifier with preg_replace is supposed to evaluate the replacement term 
prior to doing the replace. The problem is that it chokes with errors when the term to 
be evaluated contains quotes. 

Try using "e" to evaluate a PHP expression like: 

strtoupper("this phrase has spaces")

It gives an error:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in 
framework_func.php(15) : regexp code on line 1

Parse error: parse error in framework_func.php(15) : regexp code on line 1

Fatal error: Failed evaluating code: strtoupper(\"This phrase has spaces\") in 
framework_func.php on line 15

However, it WILL allow you to pass a string with no quotes, as long as it doesn't have 
spaces! As an example, I use this bit of code to to allow any term enclosed in curlies 
in a string to be evaluated as PHP:

preg_replace("/(\{)(.*?)(\})/e", "$2", $string);

If $string contains "{strtoupper(no_spaces)}", that term will be replaced with 
"NO_SPACES" upon execution of the preg_replace. So far so good.

But it fails with "{strtoupper(has spaces, no quotes)}" AND with "{strtoupper("has 
spaces and quotes")}. Of course, the latter is the way one would expect it to work, 
because it's valid PHP. 

I have hopes that the new function preg_replace_callback will allow me to work around 
this, but it seems as if the e modifier should allow you to evaluate ANY legal PHP 

Sorry if this is already known or is not considered a bug.

Edit Bug report at:

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to