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

From: Date: Fri, 05 May 2000 13:55:36 +0000
Subject: Re: preg_replace and e option (bug or feature?)
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-18452@lists.php.net to get a copy of this message
At 08:46 5-5-2000 -0500, Andrei Zmievski wrote:
On Fri, 05 May 2000, Wico de Leeuw wrote: take this text: $text = "#!this 'is' a \"test\" :)!#"; say i want everyting between #! and !# feed and replace to addslashes you sould say i do : $new_text = preg_replace("'#!(.*?)!#'ie", 'Addslashes("\\1")', $text); but because of the " and the ' this will fall due the eval of preg_replace resulting in a: Parse error: parse error in Unknown on line 0 i suggest the founded strings in the regular can be called like this to overcome this problem: $new_text = preg_replace("'#!(.*?)!#'ie", 'Addslashes($1)', $text); Anyone has comment on this? Yes, you should first escape ' or " in your original text with one preg_replace() and then use another with /e modifier to feed it to your function.
Wouldn't it be easyer if php would just putt it also in the var $1 wich you can pass to the function? btw if i would fist escape the ' an " in a preg_replace i wouldn't need the second to do an addslashes on it :) but the addslashes was just for the example.. and to give you some stuff to thing about the e option in preg_repace Wico
-Andrei * The future has arrived, it's just not evenly distributed. -W. Gibson *


« previous php.dev (#18452) next »