Properties

$contentLength

$contentLength : int

待检测语句长度

Type

int

$wordTree

$wordTree : \util\HashMap|null

铭感词库树

Type

HashMap|null

$badWordList

$badWordList : array|null

存放待检测语句铭感词

Type

array|null

$_instance

$_instance : object|null

敏感词单例

Type

object|null

Methods

init()

init() : self

获取单例

Returns

self —

setTreeByFile()

setTreeByFile(string  $filepath = '') : $this

构建铭感词树【文件模式】

Parameters

string $filepath

Throws

\Exception

Returns

$this —

setTree()

setTree(null  $sensitiveWords = null) : $this

构建铭感词树【数组模式】

Parameters

null $sensitiveWords

Throws

\Exception

Returns

$this —

getBadWord()

getBadWord(string  $content, int  $matchType = 1, int  $wordNum) : array

检测文字中的敏感词

Parameters

string $content

待检测内容

int $matchType

匹配类型 [默认为最小匹配规则]

int $wordNum

需要获取的敏感词数量 [默认获取全部]

Returns

array —

replace()

replace( $content, string  $replaceChar = '', bool  $repeat = false, int  $matchType = 1) : mixed

替换敏感字字符

Parameters

$content

文本内容

string $replaceChar

替换字符

bool $repeat

true=>重复替换为敏感词相同长度的字符

int $matchType

Returns

mixed —

mark()

mark( $content, string  $sTag, string  $eTag, int  $matchType = 1) : mixed

标记敏感词

Parameters

$content

文本内容

string $sTag

标签开头,如

string $eTag

标签结束,如

int $matchType

Returns

mixed —

islegal()

islegal( $content) : bool

被检测内容是否合法

Parameters

$content

Returns

bool —

yieldToReadFile()

yieldToReadFile(mixed  $filepath) : mixed

Parameters

mixed $filepath

Returns

mixed —

buildWordToTree()

buildWordToTree(mixed  $word = '') : mixed

Parameters

mixed $word

Returns

mixed —

dfaBadWordConversChars()

dfaBadWordConversChars( $word,  $char) : string

敏感词替换为对应长度的字符

Parameters

$word
$char

Returns

string —