wp_kses_named_entities()
云策文档标注
概述
wp_kses_named_entities() 是 wp_kses_normalize_entities() 正则表达式的回调函数,用于处理有效的命名实体引用,确保其符合 HTML 和 XML 验证器的严格标准。
关键要点
- 该函数仅接受有限、区分大小写且经过严格审查的命名实体引用。
- 参数 $matches 是 preg_replace_callback() 的匹配数组,必需。
- 返回正确编码的实体字符串。
- 函数内部使用全局变量 $allowedentitynames 来验证实体是否允许。
- 如果 $matches[1] 为空,则返回空字符串。
- 自 WordPress 3.0.0 版本引入。
代码示例
function wp_kses_named_entities( $matches ) {
global $allowedentitynames;
if ( empty( $matches[1] ) ) {
return '';
}
$i = $matches[1];
return ( ! in_array( $i, $allowedentitynames, true ) ) ? "&$i;" : "&$i;";
}
原文内容
Callback for wp_kses_normalize_entities() regular expression.
Description
This function only accepts valid named entity references, which are finite, case-sensitive, and highly scrutinized by HTML and XML validators.
Parameters
$matchesarrayrequired-
preg_replace_callback() matches array.
Source
function wp_kses_named_entities( $matches ) {
global $allowedentitynames;
if ( empty( $matches[1] ) ) {
return '';
}
$i = $matches[1];
return ( ! in_array( $i, $allowedentitynames, true ) ) ? "&$i;" : "&$i;";
}
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |