Home  >  Article  >  Backend Development  >  How to use PHP+Ajax to determine whether there are sensitive words

How to use PHP+Ajax to determine whether there are sensitive words

little bottle
little bottleforward
2019-04-17 09:28:132370browse

This article describes how to use PHP and Ajax to create a method for filtering sensitive words and determine whether there are sensitive words.

How to use PHP+Ajax to determine whether there are sensitive words

Sensitive vocabulary array sensitive.php


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

jQuery AjaxDetermine whether there are sensitive words【Related tutorials : AJAX Video Tutorial jQuery Video Tutorial


 1 $("#add").click(function() { 
 2     var content = $("#content").val(); 
 3     $.ajax({ 
 4         type: "POST", 
 5         url: "ajax.php", 
 6         data: "content=" + content, 
 7         success: function(data) { 
 8             if (data) { 
 9                 $("#message").html(data).show(); 
10             } else { 
11                 $("#message").html('没有敏感词汇').show(); 
12             } 
13         } 
14     }); 
15 });

PHP determines whether there are sensitive words in the array, if so Then output


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

[Related video: PHP video tutorial]

The above is the detailed content of How to use PHP+Ajax to determine whether there are sensitive words. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete