定制 devtrope/profanity-filter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devtrope/profanity-filter

最新稳定版本:v0.0.4

Composer 安装命令:

composer require devtrope/profanity-filter

包简介

A profanity filter for PHP

README 文档

README

A lightweight and customizable PHP package for detecting and censoring profanity in text.
Includes multiple sensitivity levels, support for custom word lists, and is PSR-12 and PHPStan compatible.

Latest Stable Version License: MIT Static Analysis: PHPStan Code Style: PSR-12 Downloads PHP Version

Features

  • Detects offensive words in strings
  • Supports multiple filtering levels: low, medium, high
  • Supports multiple languages (en, fr)
  • Custom blacklist support via JSON file
  • Add or remove words dynamically at runtime
  • Fully typed and ready for static analysis
  • Easy integration with existing projects

Installation

Install via Composer:

composer require devtrope/profanity-filter

Usage

Basic usage

use ProfanityFilter\ProfanityFilter;
use ProfanityFilter\ProfanityLevel;

$filter = new ProfanityFilter();
$text = "You little piece of shit!";
echo $filter->clean($text); // You little piece of ****!

With a specific language

$filter = new ProfanityFilter(ProfanityLevel::HIGH, 'fr');

With a custom blacklist

$filter = new ProfanityFilter(
    ProfanityLevel::HIGH,
    'fr',
    __DIR__ . '/my-custom-blacklist.json'
);
{
    "low": ["wordlow"],
    "medium": ["wordmedium"],
    "high": ["wordhigh"]
}

Add or remove words at runtime

$filter->addWord('uglyword');
$filter->removeWord('otheruglyword');

Check if a text contains profanity

if ($filter->containsProfanity($text)) {
    echo "Inappropriate content detected!";
}

Language support

Currently supported locales:

  • en - English
  • fr - Français

Profanity levels

Each level includes all words from the previous level:

Level Description
LOW Mild profanity
MEDIUM Default, balanced
HIGH Agressive filtering

License

MIT License - see LICENSE for details.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-08-07