note 90315 added to function.preg-quote
| From: | strata_ranger at hotmail dot com | Date: | Thu, 16 Apr 2009 04:09:53 +0000 |
| Subject: | note 90315 added to function.preg-quote | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153371@lists.php.net to get a copy of this message | ||
In response to Frostschutz, the hyphen is not the only 'semi-special' character in PCRE
that preg_quote doesn't modify. Remember, the hyphen is a special character /only/ when it
occurs inside a character class (e.g. '[A-Z]'), if it occurs outside a character class it
is treated literally.
Two more 'semi-special' PCRE characters are:
(space) and # -- If the PCRE_EXTENDED option is set, whitespace is ignored (outside of a character
class) and # delimits comments.
Since PCRE allows you to escape /any/ non-alphanumeric character via backslash, it could be nice if
preg_quote() had an option to do the same.
Of course, if that's what you need to do you can always do something like this:
<?php
// Escape any/all non-alphanumeric characters with a \
$string = preg_replace('/[^a-z\d]/i', '\$1', $string);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 76.2.25.104
----
Manual Page -- http://www.php.net/manual/en/function.preg-quote.php
Edit -- https://master.php.net/note/edit/90315
Del: integrated -- https://master.php.net/note/delete/90315/integrated
Del: useless -- https://master.php.net/note/delete/90315/useless
Del: bad code -- https://master.php.net/note/delete/90315/bad+code
Del: spam -- https://master.php.net/note/delete/90315/spam
Del: non-english -- https://master.php.net/note/delete/90315/non-english
Del: in docs -- https://master.php.net/note/delete/90315/in+docs
Del: other reasons-- https://master.php.net/note/delete/90315
Reject -- https://master.php.net/note/reject/90315
Search -- https://master.php.net/manage/user-notes.php