esc_attr()
esc_attr( string $text ) 为HTML属性转义。Escaping for HTML at…
esc_attr( string $text )
为HTML属性转义。
Escaping for HTML attributes.
目录锚点:#参数#返回#源码#笔记
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $text | (string) | 必需 |
返回(Return)
(string)
源码(Source)
/**
* Escaping for HTML attributes.
*
* @since 2.8.0
*
* @param string $text
* @return string
*/
function esc_attr( $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 an HTML attribute.
*
* Text passed to esc_attr() is stripped of invalid or special characters
* before output.
*
* @since 2.0.6
*
* @param string $safe_text The text after it has been escaped.
* @param string $text The text prior to being escaped.
*/
return apply_filters( 'attribute_escape', $safe_text, $text );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.8.0 | wp-includes/formatting.php:4481 | 276 | 4 |
笔记(Notes)
在转义接受uri的属性的值(例如,ref和src)时,必须通过esc_url()传递该值。如果只使用esc_attr(),则代码可能仍然易受XSS攻击。(还要注意,使用esc_url()时,不需要同时使用esc_attr()。)
输出时转义$POST数据的示例
使用esc_attr()转义属性时,务必在属性值周围使用引号。否则,您的代码仍然容易受到XSS的攻击。
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。



还没有任何评论,赶紧来占个楼吧!