This article describes the PHP filtering blacklist keyword method. Share to everyone for your reference. The implementation methods are as follows:
Keyword filtering is very simple to filter the content to exist in an array or document, and then the user submitted when we preg_match or istrpos judgment can be resolved, the specific methods are as follows.
The instance code is as follows:
Copy Code code as follows:
Filter blacklist keyword functions
function Check_ ($data) {
$keywords = "Are you the Great God | hello | to die";
if (Preg_match ("/$keywords/I", $data)) {
Return
}else{
return $data;
}
}
Keywords are stored in such a form as txt,txt files: | gambling machine | selling Blood | sell the Kidney | Sell the Organ | Cornea, the code is as follows:
Copy Code code as follows:
<?php
function Filter_word ($STR, $fileName)
{
if (!) ( $words = file_get_contents ($fileName))) {
Die (' file read error! ');
}
$str = Strtolower ($STR);
Var_dump ($words);
$word = Preg_replace ("/[1,2,3] | /i ", ', $words);
$wor = substr ($word, 0,-1);
$w = Preg_replace ("|/|i", '/', $word);
echo "<pre>";
Var_dump ($w);
$words = "Aaa|bbb|ccc|ddd|eee";
$matched = preg_replace ('/'. $word. /I ', ' * * * ', $string);
return $matched;
}
$content = "<a href= ' > I want to aaafsdfbbb</a>";
if ($result = Filter_word ($content, './words.txt ')) {
echo $result;
echo "Replace success";
}else{
echo "Replace failed!";
?>
I hope this article will help you with your PHP program design.