本文讲述如何使用PHP和Ajax创建一个过滤敏感词汇的方法,判断是否有敏感词汇。

PHP+Ajax判断是否有敏感词汇-LMLPHP

敏感词汇数组sensitive.php

 return array (
0 => '111111',
1 => 'aaaaaa',
2 => 'bbbbbb',
3 => 'ccccc',
4 => 'dddd',
5 => 'eeee',
........
)

判断是否有敏感词汇

 $("#add").click(function() {
var content = $("#content").val();
$.ajax({
type: "POST",
url: "ajax.php",
data: "content=" + content,
success: function(data) {
if (data) {
$("#message").html(data).show();
} else {
$("#message").html('没有敏感词汇').show();
}
}
});
});

PHP判断数组里是否有敏感词汇,若是有则输出

 $content = htmlspecialchars($_POST['content']);
$arr= include 'sensitive.php';
foreach ($arr as $v) {
if (false !== strstr($content, $v)){
echo "含有敏感词汇 ".$v;
exit;
}
}

实例下载:https://www.sucaihuo.com/php/814.html

04-17 21:06