note 21368 added to function.preg-replace
| From: | vivin at asu dot edu | Date: | Fri, 10 May 2002 00:25:52 +0000 |
| Subject: | note 21368 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30408@lists.php.net to get a copy of this message | ||
A little quirk I noted. I was trying to replace all instances of \ with \ and ran into the
following problems:
$Entry = preg_replace("/\\/", "\", $Entry);
(this gave: Warning: No ending delimiter '/' found)
$Entry = preg_replace("/(\\)/", "\", $Entry);
(this gave: Warning: Compilation failed: missing ) at offset 3)
$Entry = preg_replace("/[\\]/", "\", $Entry);
(this gave: Warning: Compilation failed: missing terminating ] for character class at offset 3)
For some reason, it escapes the ), ] or /...
I finally got it to work when I did this:
$Entry = preg_replace("/[(\\)]/", "\", $Entry);
I don't know if anyone posted this before... I'm not all that fluent in PHP or regex, so
please excuse any mistakes... (or if what I said seems glaringly obvious)
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+21368
http://master.php.net/manage/user-notes.php?action=delete+21368
http://master.php.net/manage/user-notes.php?action=reject+21368