Bug #10228 Updated: preg_replace with e modifier barfs on quotes
| From: | andrei@php.net | Date: | Thu, 12 Apr 2001 21:10:54 +0000 |
| Subject: | Bug #10228 Updated: preg_replace with e modifier barfs on quotes | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-51513@lists.php.net to get a copy of this message | ||
ID: 10228
Updated by: andrei
Reported By: dbrewer@insightpd.com
Old-Status: Open
Status: Assigned
Bug Type: Regexps related
PHP Version: 4.0.4
Assigned To: andrei
Comments:
Previous Comments:
---------------------------------------------------------------------------
[2001-04-07 18:35:09] dbrewer@insightpd.com
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 fragment.
Sorry if this is already known or is not considered a bug.
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=10228&edit=2