敏感词过滤的php代码,ThinkPHP敏感词汇过滤
如果內(nèi)容中包含敏感詞匯,則返回False,否則返回True。
很簡(jiǎn)單的代碼。
請(qǐng)將文件放置于 "項(xiàng)目/ORG/SensitiveFilter.class.php"下。
其中 “ SensitiveThesaurus.php”是一個(gè)敏感詞匯數(shù)組,大家可以任意添加內(nèi)容。
1.[代碼][PHP]代碼<?php
/**
* 敏感詞匯過(guò)濾
* User: konakona
* Date: 12-11-28
* Time: 下午4:37
* 調(diào)用方式
* if(false === SensitiveFilter::filter($content)){
* error("含有敏感詞匯");
* }
*/
class SensitiveFilter extends Think{
public static $wordArr = array();
public static $content = "";
/**
* 處理內(nèi)容
* @param $content
*
* @return bool
*/
public static function filter($content){
if($content=="") return false;
self::$content = $content;
empty(self::$wordArr)?self::getWord():"";
foreach ( self::$wordArr as $row){
if (false !== strstr(self::$content,$row)) return false;
}
return true;
}
public static function getWord(){
self::$wordArr = include 'SensitiveThesaurus.php';
}
}
2.[文件]
SensitiveThesaurus.php
3.[圖片] 被攔截.jpg
本文原創(chuàng)發(fā)布php中文網(wǎng),轉(zhuǎn)載請(qǐng)注明出處,感謝您的尊重!
總結(jié)
以上是生活随笔為你收集整理的敏感词过滤的php代码,ThinkPHP敏感词汇过滤的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 文章目录自动生成器
- 下一篇: 和县机电工程学校工业机器人_【校企合作】