Hi all,

At the moment I'm doing this to escape all "special" regular expression
characters from my regex string:

   $badwordtest = str_replace("/","",$badwordtest);
   $badwordtest = str_replace("\\","",$badwordtest);
   $badwordtest = str_replace("^","\^",$badwordtest);
   $badwordtest = str_replace(".","\.",$badwordtest);
   $badwordtest = str_replace("[","\[",$badwordtest);
   $badwordtest = str_replace("$","\$",$badwordtest);
   $badwordtest = str_replace("(","\(",$badwordtest);
   $badwordtest = str_replace(")","\)",$badwordtest);
   $badwordtest = str_replace("|","\|",$badwordtest);
   $badwordtest = str_replace("*","\*",$badwordtest);
   $badwordtest = str_replace("+","\+",$badwordtest);
   $badwordtest = str_replace("?","\?",$badwordtest);
   $badwordtest = str_replace("{","\{",$badwordtest);
   $badwordtest = str_replace("}","\}",$badwordtest);
   $badwordtest = str_replace("\\","\\",$badwordtest);
   $badwordtest = "/" . $badwordtest . "/i";

   if (preg_match($badwordtest,$word)) {
    $directmatch = TRUE;

Is there a way to either do this all in one go or even better, have the ereg
itself ignore those characters if they are contained in the string? The idea
is that I want to check a word for swearing by doing a direct comparison
with a list of swear words, however the word I check could easily contain a
special character so I need to escape it before the test commences.

Suggestions very welcome!


Fatal Design
Atari / DarkBASIC / Coding / Since 1995

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to