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

little bottle
Release: 2023-04-05 21:30:01
forward
2367 people have browsed it

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 )
Copy after login

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 });
Copy after login

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 }
Copy after login

[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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!