Blogger Information
Blog 14
fans 0
comment 0
visits 12004
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP+Ajax判断是否有敏感词汇
alber1986的博客
Original
848 people have browsed it

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

222222.png

敏感词汇数组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

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post