esc_html()
esc_html( string $text )
为HTML块转义。
Escaping for HTML blocks.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$text | (string) | 必需 |
返回(Return)
(string)
源码(Source)
/** * Escaping for HTML blocks. * * @since 2.8.0 * * @param string $text * @return string */ function esc_html( $text ) { $safe_text = wp_check_invalid_utf8( $text ); $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); /** * Filter a string cleaned and escaped for output in HTML. * * Text passed to esc_html() is stripped of invalid or special characters * before output. * * @since 2.8.0 * * @param string $safe_text The text after it has been escaped. * @param string $text The text prior to being escaped. */ return apply_filters( 'esc_html', $safe_text, $text ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
2.8.0 | wp-includes/formatting.php:4456 | 161 | 4 |
笔记(Notes)
实例
请注意,escu html将尝试避免双重编码。获取此代码:
对示例字符串使用esc_html()之后,您将拥有:
esc_html() 为WP2原创文章,链接:https://www.wp2.cn/functions/esc_html-2/