note 66016 deleted from function.preg-replace by nlopess
| From: | nlopess@php.net | Date: | Fri, 12 May 2006 08:59:50 +0000 |
| Subject: | note 66016 deleted from function.preg-replace by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-111169@lists.php.net to get a copy of this message | ||
Note Submitter: Elias: coaxyal at gmail dot com
----
This function like as str_replace ('"', '\\"', $string), but if \\
already exsist before " - they do not execute.
<?php
preg_replace ('/(?<!\\\\\\\\)"/', '\\"', $string);
?>
Examples:
<?php
echo 'example 1: ' . preg_replace ('/(?<!\\\\\\\\)"/',
'\\"', 'name="test"') . '<BR />';
echo 'example 2: ' . preg_replace ('/(?<!\\\\\\\\)"/',
'\\"', 'name=\\"test\\"') . '<BR />';
echo 'example 3: ' . str_replace ('"', '\\"',
'name=\\"test\\"') . '<BR />';
?>
The above example will output:
example 1: name=\\"test\\"
example 2: name=\\"test\\"
example 3: name=\\\\"test\\\\"