php关键词拦截程序,拦截后如何知道哪个词为非法词组
php关键词拦截程序,拦截后怎么知道哪个词为非法词组?
一、panduan.php
/**
* 判断文本中是否存在关键词
*/
function filter_text($text, $badstring){
$filter = explode('|', $badstring);
foreach ($filter as $key) {
if(strpos($text, $key) !== false){
return true;
}
}
return false;
}
?>
二、filter.php
$badstring="拦我|此内容|不允许";
?>
三、index.php
require_once("panduan.php");
require_once("filter.php");
$biaoti="如果包含此内容就不能通过!";
if(filter_text($biaoti, $badstring)){
echo "对不起,你提示的内容包含“$*****”文字不能表,请删除“此内容”文字后再提交!";
exit();
}
?>
以上代码能正确拦截事先设置好的关键词,但怎么写才能提示是哪个关键词非法的?如果取得引号中的内容:“$*****”?
请高手帮忙,谢谢!
------解决方案--------------------
在这里修改成
if(strpos($text, $key) !== false){
return $key;
}
这里
if(filter_text($biaoti, $badstring)){
echo "对不起,你提示的内容包含“$*****”文字不能表,请删除“此内容”文字后再提交!";
exit();
}
修改成
$badstr=filter_text($biaoti, $badstring);
if($badstr){
echo "对不起,你提示的内容包含“.$badstr.”文字不能表,请删除“此内容”文字后再提交!";
exit();
}
大约如此.
------解决方案--------------------
- PHP code
$text = '拦我'; $badstring = "/拦我|此内容|不允许/"; if (preg_match($badstring, $text, $matchs)){ echo $matchs[0]; //var_dump($matchs); } <br><font color="#e78608">------解决方案--------------------</font><br> <strong>关于二者的效率</strong><br><br>测试代码:<br>
- PHP code
$start = microtime(true); $text = '拦我'; $badstring = "/拦我|此内容|不允许/"; $count = 0; for($i = 0; $i

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
