Created
February 11, 2020 23:01
-
-
Save wilnaweb/52e118c4dce4ba075f4011191d6897c5 to your computer and use it in GitHub Desktop.
Check if exist bad words blacklist in string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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