PHP 8.4.22 Released!

Spoofchecker::setAllowedChars

(PHP 8 >= 8.4.0)

Spoofchecker::setAllowedCharsSet the set of characters allowed when running checks

说明

public function Spoofchecker::setAllowedChars(string $pattern, int $patternOptions = 0): void

Restricts the characters that are considered acceptable by subsequent checks to the set described by pattern. Any character outside of this set causes Spoofchecker::isSuspicious() to report a result.

参数

pattern
A character set described as a UnicodeSet pattern, that is a regular-expression style character class. It must begin with [ and end with ], for example [a-z0-9].
patternOptions
A bitmask controlling how pattern is interpreted. It must be 0, or Spoofchecker::IGNORE_SPACE on its own or combined with exactly one of Spoofchecker::CASE_INSENSITIVE, Spoofchecker::ADD_CASE_MAPPINGS, or Spoofchecker::SIMPLE_CASE_INSENSITIVE.

返回值

No value is returned.

错误/异常

Throws a ValueError if pattern is not a valid character set pattern, or if patternOptions is not a valid combination of options.

示例

示例 #1 Spoofchecker::setAllowedChars() example

<?php
$checker
= new Spoofchecker();
$checker->setAllowedChars('[a-z0-9]');

var_dump($checker->isSuspicious('hello'));
var_dump($checker->isSuspicious('héllo'));
?>

以上示例会输出:

bool(false)
bool(true)

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top