_wp_has_noncharacters_fallback()
云策文档标注
概述
_wp_has_noncharacters_fallback() 是 WordPress 中的一个函数,用于检测字符串是否包含 Unicode 非字符,作为后备支持。它通过扫描字符串中的 UTF-8 字节序列来实现此功能。
关键要点
- 函数用途:检测字符串中是否存在 Unicode 非字符,返回布尔值。
- 参数:接受一个必需的字符串参数 $text,表示要检查的文本。
- 返回值:如果找到非字符则返回 true,否则返回 false。
- 相关函数:与 wp_has_noncharacters() 和 _wp_scan_utf8() 相关,后者用于查找字符串中有效和无效的 UTF-8 字节范围。
- 版本历史:在 WordPress 6.9.0 版本中引入。
代码示例
function _wp_has_noncharacters_fallback( string $text ): bool {
$at = 0;
$invalid_length = 0;
$has_noncharacters = false;
$end = strlen( $text );
while ( $at < $end ) {
// 扫描逻辑(此处省略具体实现细节)
}
return $has_noncharacters;
}
原文内容
Fallback support for determining if a string contains Unicode noncharacters.
Description
See also
Parameters
$textstringrequired-
Are there noncharacters in this string?
Source
function _wp_has_noncharacters_fallback( string $text ): bool {
$at = 0;
$invalid_length = 0;
$has_noncharacters = false;
$end = strlen( $text );
while ( $at < $end && ! $has_noncharacters ) {
_wp_scan_utf8( $text, $at, $invalid_length, null, null, $has_noncharacters );
$at += $invalid_length;
}
return $has_noncharacters;
}
Changelog
| Version | Description |
|---|---|
| 6.9.0 | Introduced. |