Skip to main content
Post Made Community Wiki by samliew
Copy edited (e.g. ref. <http://english.stackexchange.com/questions/4645/is-it-ever-correct-to-have-a-space-before-a-question-or-exclamation-mark#comment206109_4645>).
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134

ifIf you want to check if the string containcontains several specifics words, you can do  :

$badWords = array("dette", "capitale", "rembourser", "ivoire", "mandat");

$string = "a string with the word ivoire";

$matchFound = preg_match_all("/\b(" . implode($badWords,"|") . ")\b/i", $string, $matches);
            
if ($matchFound) {
    echo "a bad word has been found";
} 
else {
    echo "your string is okay";
}

This is usefulluseful to avoid spam when sending emails for example.

if you want to check if the string contain several specifics words, you can do  :

$badWords = array("dette","capitale","rembourser","ivoire","mandat");

$string = "a string with the word ivoire";

$matchFound = preg_match_all("/\b(" . implode($badWords,"|") . ")\b/i",$string,$matches);
            
if($matchFound){
  echo "a bad word has been found";
}else{
  echo "your string is okay";
}

This is usefull to avoid spam when sending emails for example.

If you want to check if the string contains several specifics words, you can do:

$badWords = array("dette", "capitale", "rembourser", "ivoire", "mandat");

$string = "a string with the word ivoire";

$matchFound = preg_match_all("/\b(" . implode($badWords,"|") . ")\b/i", $string, $matches);

if ($matchFound) {
    echo "a bad word has been found";
} 
else {
    echo "your string is okay";
}

This is useful to avoid spam when sending emails for example.

Source Link
Julien
  • 4.2k
  • 10
  • 43
  • 72

if you want to check if the string contain several specifics words, you can do :

$badWords = array("dette","capitale","rembourser","ivoire","mandat");

$string = "a string with the word ivoire";

$matchFound = preg_match_all("/\b(" . implode($badWords,"|") . ")\b/i",$string,$matches);
            
if($matchFound){
  echo "a bad word has been found";
}else{
  echo "your string is okay";
}

This is usefull to avoid spam when sending emails for example.