Re: preg_replace and e option (bug or feature?)

From: Date: Fri, 05 May 2000 13:57:05 +0000
Subject: Re: preg_replace and e option (bug or feature?)
References: 1 2 3 4  Groups: php.dev 
Request: Send a blank email to php-dev+get-18453@lists.php.net to get a copy of this message
On Fri, 05 May 2000, Wico de Leeuw wrote: > Wouldn't it be easyer if php would just putt it also in the var $1 wich you > can pass to the function? No, it wouldn't really solve your problem. Internally, when you call preg_replace() with /e PHP constructs a string to be evaluated by substituting the captured subpatterns in place of \\n. So, even if you used $1 and AddSlashes($1), internally, it would end up being: AddSlashes('foo' and "not" 'foo') (or something like that) This string is passed off to Zend for evaluation and Zend, of course, fails because of the parser error. Even if you do AddSlashes("$1"), you are not safe because then you have a different parse error due to quotes (and "$1" is the same as "\\1", for all it matters). > btw if i would fist escape the ' an " in a preg_replace i wouldn't need the > second to do an addslashes on it :) So, just use preg_replace() to do what addslashes() does. $text = preg_replace("/['"]/", "\\\\0", $text); -Andrei 'Any given program, when running correctly, is obsolete.' - First Law of Computer Programming

« previous php.dev (#18453) next »