tbetool/spam-doctor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tbetool/spam-doctor

Composer 安装命令:

composer require tbetool/spam-doctor

包简介

Prevent your email from being spammed. PHP Library to check for whether content contains spam words.

README 文档

README

Check your email content for spam possibilities before being spammed. PHP Library to check if content contains spam words.

Using the Library

Installation

Intall library in PHP project using composer

composer require tbetool/spam-doctor

Using Library

$spamDoctor = new SpamDoctor();

$spamDoctor->check($text_content);

check() parameters

  1. text_content: Text content to check for spam. You can pass both plain text and html content
  2. is_html (boolean): if text_content is HTML, set second parameter to true. Default: false.

Get output

$spamDoctor->getSpamItems();

returns array of spam keyword and their count of occurrences.

[
   0 => [
     item => 'welcome',
     count => 4
   ]
]
$spamDoctor->getSpamPositions();

returns array of positions of the spam items in ascending order.

[
   0 => 4,
   1 => 12,
   2 => 25
]
$spamDoctor->getHighlighted();

returns complete string with spam keywords highlighted in red color. If HTML content is provided to check, this will return only the text of the HTML content.
To get HTML content highlighted, pass true as parameter.

$spamDoctor->getHighlighted(true);

returns complete HTML content with spam keywords highlighted.

$spamDoctor->getSpamDictionary();

returns array of complete list of words used to detect spam contents.

Replace Rule

Library also support replace rule which can be used to replace spamming text on the go. You can pass json rule in key-value pair where key in the spam text is replaced by the corresponding value.

To set the replace rule, use following function before calling check()

$replace_rule = [
    'o' => 0,
    'O' => 0,
    '*' => '_'
];

$replace_rule = json_encode($replace_rule);

$spamDoctor->setReplaceRule($replace_rule);

Above example will replace o and O (upper and lowercase of O) with 0 (zero)

You can also pass common letter to replace with if letter in replace_rule is not found by passing * key with appropriate value.

For example, in above example if a spam word contains o or *O will be replaced with 0 otherwise will add _ (underscore) to random place in the word.

Self Learning

This library learns itself as it processes the spam contents. It generates a dictionary file in data directory name spam_data.txt.

You can also teach the doctor by passing json data to the teachDoctor() function.

$spamDoctor->teachDoctor($json_data);

NOTE: Json data can be upto 2-Dimensional array

Exception Handling

Ex:

try {
    $spamDoctor->check($html_content, true);
} catch (Exception $exception) {
    echo $exception->getMessage();
}

Bug Reporting

If you found any bug, create an issue.

Support and Contribution

Something is missing?

  • Fork the repositroy
  • Make your contribution
  • make a pull request

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2018-10-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固