note 48606 added to function.preg-replace

From: Date: Sat, 01 Jan 2005 15:26:09 +0000
Subject: note 48606 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-82538@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48606 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48606&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48606&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48606&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48606&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48606&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48606&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48606&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82538) next »