note 30055 deleted from function.preg-match by jome
| From: | jome@php.net | Date: | Fri, 30 Sep 2005 18:56:30 +0000 |
| Subject: | note 30055 deleted from function.preg-match by jome | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96078@lists.php.net to get a copy of this message | ||
Note Submitter: kevin dot bro at hostedstuff dot com
----
As Carlos points out (2 comments above) you don't want people to mess around with your regexp.
To avoid this I use this preg_addslashes function:
<?
function preg_addslashes ($foo)
{
return preg_replace("/([^A-z0-9_-]|[\\\[\]])/", "\\\\\\1", $foo);
}
$foo = "([/com|et\])";
$true = preg_match ("/^".preg_addslashes($foo)."$/", $foo);
// without preg_addslashes you'd get an error and $true = false.
?>