Вопрос

Currently I have a simple swear filter in place with an array of words, I am now also wanting to do checking on strings to see if they contain any:

Here's my list:

$words = array(
"/foo/is",
"/bar/is",
"/baz/is"
);

So I basically want to search a string for any of those words, if it picks up even one of them, then do something.

Is that easily doable?

Это было полезно?

Решение

did you mean something like:

$words = array(
    "/foo/is",
    "/bar/is",
    "/baz/is"
);

$myWord = 'hello';

foreach($words as $check) {
   if (preg_match($check, $myWord )) {
       // do something
   }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top