note 89720 added to function.preg-quote
| From: | frostschutz at osu1 dot php dot net | Date: | Fri, 20 Mar 2009 10:01:13 +0000 |
| Subject: | note 89720 added to function.preg-quote | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152187@lists.php.net to get a copy of this message | ||
I wanted to escape a string of characters so I could match them in [], i.e.
[.,-!"§$%\\\[\]\^].
Unfortunately preg_quote does not escape the - character which has a special meaning in [], i.e.
[a-z].
So I used this hack: make - the delimiter of the expression, i.e.
preg_quote(userinput, "-")
preg_replace("-[$userinput]-u", "", $str)
Apparently using a special char as a delimiter of a regular expression disables this character, i.e.
even if it's escaped it's not understood as special character for the expression anymore.
so the pattern "-[a\\-z]-u" matches the characters a, - and z, and not abc...xyz.
It would be nice if preg_quote also escaped characters that have special meanings even if they have
this meaning only under certain conditions, such as inside [].
----
Server IP: 212.124.37.9
Probable Submitter: 93.211.36.37
----
Manual Page -- http://www.php.net/manual/en/function.preg-quote.php
Edit -- https://master.php.net/note/edit/89720
Del: integrated -- https://master.php.net/note/delete/89720/integrated
Del: useless -- https://master.php.net/note/delete/89720/useless
Del: bad code -- https://master.php.net/note/delete/89720/bad+code
Del: spam -- https://master.php.net/note/delete/89720/spam
Del: non-english -- https://master.php.net/note/delete/89720/non-english
Del: in docs -- https://master.php.net/note/delete/89720/in+docs
Del: other reasons-- https://master.php.net/note/delete/89720
Reject -- https://master.php.net/note/reject/89720
Search -- https://master.php.net/manage/user-notes.php