PHP code example of jmhc / sensitive

1. Go to this page and download the library: Download jmhc/sensitive library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jmhc / sensitive example snippets


use Jmhc\Sensitive\SensitiveService;

// 实例化服务
$sensitive = new SensitiveService();
// 设置敏感字符串数组
$sensitive->setSensitiveWords([]);
// 设置排除字符串数组
$sensitive->setExceptWords([]);
// 使用敏感词库,默认使用
$sensitive->withSensitiveWordLibrary(true);
// 验证,有敏感词会抛出 Jmhc\Sensitive\SensitiveException 异常
$sensitive->validate('这是需要验证的字符串', '错误消息前缀');