note 30055 added to function.preg-match
| From: | kevin dot bro at hostedstuff dot com | Date: | Wed, 05 Mar 2003 12:26:35 +0000 |
| Subject: | note 30055 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44873@lists.php.net to get a copy of this message | ||
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.
?>
--
http://www.php.net/manual/en/function.preg-match.php
http://master.php.net/manage/user-notes.php?action=edit+30055
http://master.php.net/manage/user-notes.php?action=delete+30055
http://master.php.net/manage/user-notes.php?action=reject+30055