note 102501 deleted from reference.pcre.pattern.modifiers by danbrown

From: Date: Fri, 18 Feb 2011 13:35:18 +0000
Subject: note 102501 deleted from reference.pcre.pattern.modifiers by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177114@lists.php.net to get a copy of this message
Note Submitter: chenliq at gmail dot com ---- Single quotes, double quotes, backslashes (\) and NULL chars will be escaped by backslashes in substituted backreferences. <?php $test['test'] = 'test string to replace...'; $str = "{\$test['test']}"; $reg = '~{(\$[a-z_][\w_]*' .'(?:\[[\S]+?\])*' .")}~e"; $replace = '\\1'; $str = preg_replace($reg, $replace, $str); echo $str; ?> Fatal error: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Failed evaluating code: $test[\'test\'] <?php $test['test'] = 'test string to replace...'; $str = "{\$test['test']}"; $reg = '~{(\$[a-z_][\w_]*' .'(?:\[[\S]+?\])*' .")}~e"; $replace = 'eval(\'return \\1;\')'; $str = preg_replace($reg, $replace, $str); echo $str; ?> output: test string to replace...

« previous php.notes (#177114) next »