wp_kses_html_error()
云策文档标注
概述
wp_kses_html_error() 函数用于处理 wp_kses_hair() 中的解析错误,通过正则表达式移除属性字符串中的无效部分。
关键要点
- 函数作用:处理 wp_kses_hair() 解析属性字符串时遇到的错误,清理无效内容。
- 参数:$attr(必需),表示待处理的属性字符串。
- 返回值:返回清理后的字符串。
- 实现方式:使用 preg_replace() 正则表达式匹配并移除属性字符串中的无效部分,包括引号、撇号和空白。
代码示例
function wp_kses_html_error( $attr ) {
return preg_replace( '/^("[^"]*("|$)|'[^']*('|$)|S)*s*/', '', $attr );
}
原文内容
Handles parsing errors in wp_kses_hair().
Description
The general plan is to remove everything to and including some whitespace, but it deals with quotes and apostrophes as well.
Parameters
$attrstringrequired
Source
function wp_kses_html_error( $attr ) {
return preg_replace( '/^("[^"]*("|$)|'[^']*('|$)|S)*s*/', '', $attr );
}
Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |