大网数据广告活动
PHP 语言与运行手册

Spoofchecker::setAllowedChars · Set the set of characters allowed when running checks

· 52CE 我爱测

Spoofchecker::setAllowedChars — Set the set of characters allowed when running checks

Spoofchecker::setAllowedChars

(PHP 8 >= 8.4.0)

Spoofchecker::setAllowedChars — Set the set of characters allowed when running checks

Description

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.

Parameters

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.

Return Values

No value is returned.

Errors/Exceptions

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

Examples

Example #1 Spoofchecker::setAllowedChars() example

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

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

The above example will output:

bool(false)
bool(true)

See Also

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。