note 102501 deleted from reference.pcre.pattern.modifiers by danbrown
[email protected] Fri, 18 Feb 2011 05:35:18 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
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...