Skip to content

Instantly share code, notes, and snippets.

@wilnaweb
Created February 11, 2020 23:01
Show Gist options
  • Save wilnaweb/52e118c4dce4ba075f4011191d6897c5 to your computer and use it in GitHub Desktop.
Save wilnaweb/52e118c4dce4ba075f4011191d6897c5 to your computer and use it in GitHub Desktop.
Check if exist bad words blacklist in string
#REF.: https://stackoverflow.com/questions/6284553/using-an-array-as-needles-in-strpos
function striposarray($haystack, $needles=array(), $offset=0) {
$chr = array();
foreach($needles as $needle) {
$res = stripos($haystack, $needle, $offset);
if ($res !== false) $chr[$needle] = $res;
}
if(empty($chr)) return false;
return min($chr);
}
// Blacklist Words
$blacklist = array(
'dating',
'sex',
'girls',
'crуptо',
'passivе inсоmе',
'contact us',
'legally',
'visitors',
'traffic',
'commercial offers',
'cheap',
'boost',
'bitcоin',
'engagement',
);
$banned = striposa($message, $blacklist);
if($banned !== false){
exit("Bad Word Found");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment