php过滤敏感词
<?php /** * Created by JetBrains PhpStorm. * User: lsl * Date: 13-8-28 * Time: 下午2:58 * 敏感词过滤工具类 * 使用方法 * echo FilterTools::filterContent("你妈的我操一色狼杂种二山食物","*",DIR."config/word.txt",$GLOBALS["p_memcache"]["bad_words"]); */ class FilterTools { public static $keyword = array(); /** * 从文件中加载敏感词 * @param $filename * @return array */ static function getBadWords($filename){ $file_handle = fopen($filename, "r"); while (!feof($file_handle)) { $line = trim(fgets($file_handle)); array_push(self::$keyword,$line); } fclose($file_handle); return self::$keyword; } /** * @param $content 待处理字符串 * @param $target 替换后的字符 * @param $filename 敏感词配置文件 * @param $memconfig 缓存配置文件 * @return 处理后的字符串 */ static function filterContent($content,$target,$filename,$memconfig){ $mem = new BadWordsMemcache($filename,$memconfig); $keyword = $mem->getList(); if(count($keyword) == 0){ $keyword = self::getBadWords($filename); } return strtr($content, array_combine( $keyword, array_fill(0,count($keyword), $target))); } } /** * 敏感词缓存处理类 * Class BadWordsMemcache * User: lsl */ class BadWordsMemcache{ var $memcache; var $key; var $list; var $filename; function __construct($filename,$memconfig) { $this->filename = $filename; if(!class_exists("P_Memcache")){ require_once DIR."lib/memcache.class.php"; } $this->key = "bad_words"; $this->memcache = new P_Memcache(); $this->memcache->config = $memconfig; $this->memcache->connect(); print_r($this->memcache); $this->init(); } function __destruct() { $this->memcache->close(); } /** * 初始化 * @param bool $isReset */ function init($isReset = false){ $this->list = $this->memcache->get($this->key)?$this->memcache->get($this->key):array(); if(count($this->list)==0 || $isReset){ $this->list = filterTools::getBadWords($this->filename); $this->memcache->set($this->key, $this->list); $log_data = Log::formatData($this->list); Log::logWrite($log_data, 'bad.words','init'); } } /** * 获取列表 * @return mixed */ function getList(){ return $this->list; } }
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
1 몇 달 전ByDDD
Windows 11 KB5054979의 새로운 기능 및 업데이트 문제를 해결하는 방법
3 몇 주 전ByDDD
Atomfall에서 크레인 제어 키 카드를 찾을 수 있습니다
1 몇 달 전ByDDD
KB5055523을 수정하는 방법 Windows 11에 설치되지 않습니까?
2 몇 주 전ByDDD
Inzoi : 학교 및 대학에 지원하는 방법
3 몇 주 전ByDDD

뜨거운 도구

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

드림위버 CS6
시각적 웹 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는
