What is the file sensitiveWords.php used for in PHP applications?
- 内容介绍
- 文章标签
- 相关推荐
本文共计102个文字,预计阅读时间需要1分钟。
php
public function __construct() { $this->loadSensitiveWords(); }
private function loadSensitiveWords() { // 假设敏感词存储在一个文件中,每行一个词 $filePath='sensitiveWords.txt'; if (file_exists($filePath)) { $fileContent=file_get_contents($filePath); $this->sensitiveWords=explode(PHP_EOL, $fileContent); } }
public function filter($text) { foreach ($this->sensitiveWords as $word) { $text=str_ireplace($word, str_repeat('*', strlen($word)), $text); } return $text; }}
// 使用示例$text=这是一段包含敏感词的文本;$filter=new SensitiveWordsFilter();$filteredText=$filter->filter($text);echo $filteredText;?>
sensitiveWords.php本文共计102个文字,预计阅读时间需要1分钟。
php
public function __construct() { $this->loadSensitiveWords(); }
private function loadSensitiveWords() { // 假设敏感词存储在一个文件中,每行一个词 $filePath='sensitiveWords.txt'; if (file_exists($filePath)) { $fileContent=file_get_contents($filePath); $this->sensitiveWords=explode(PHP_EOL, $fileContent); } }
public function filter($text) { foreach ($this->sensitiveWords as $word) { $text=str_ireplace($word, str_repeat('*', strlen($word)), $text); } return $text; }}
// 使用示例$text=这是一段包含敏感词的文本;$filter=new SensitiveWordsFilter();$filteredText=$filter->filter($text);echo $filteredText;?>
sensitiveWords.php
