note 48606 deleted from function.preg-replace by tularis

From: Date: Sat, 01 Jan 2005 15:30:54 +0000
Subject: note 48606 deleted from function.preg-replace by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82539@lists.php.net to get a copy of this message
Note Submitter: jw at jwscripts dot com ---- As mentioned by Yunbin Bai, when using the "e" modifier, either single or double quotes are being escaped, depending on which is used to construct the replacement argument with. Try the following example: <?php $text = 'Some \'single quoted\' and "double quoted" text<br />'; $text = preg_replace( "/(.+)/e", "substr(\"$1\", 0)", $text ); print $text; ?> This will print: Some 'single quoted' and \"double quoted\" text The best workaround is to use the preg_replace_callback() function instead, which doesn’t escape the subject string.

« previous php.notes (#82539) next »