note 90315 deleted from function.preg-quote by thiago
| From: | thiago@php.net | Date: | Thu, 16 Apr 2009 04:11:28 +0000 |
| Subject: | note 90315 deleted from function.preg-quote by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153372@lists.php.net to get a copy of this message | ||
Note Submitter: strata_ranger at hotmail dot com
----
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);
?>