sanitize_html_class
函数
sanitize_html_class ( $class, $fallback = '' )
- 参数
-
-
(string)
$class
The classname to be sanitized- Required: 是
-
(string)
$fallback
Optional. The value to return if the sanitization ends up as an empty string. Defaults to an empty string.- Required: 否
- Default: (empty)
-
(string)
- 返回值
-
- (string) The sanitized value
- 定义位置
-
-
wp-includes/formatting.php
, line 2411
-
wp-includes/formatting.php
- 引入
- 2.8.0
- 弃用
- –
Sanitizes an HTML classname to ensure it only contains valid characters.
Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty
string then it will return the alternative value supplied.
function sanitize_html_class( $class, $fallback = '' ) {
// Strip out any %-encoded octets.
$sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $class );
// Limit to A-Z, a-z, 0-9, '_', '-'.
$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );
if ( '' === $sanitized && $fallback ) {
return sanitize_html_class( $fallback );
}
/**
* Filters a sanitized HTML class string.
*
* @since 2.8.0
*
* @param string $sanitized The sanitized HTML class.
* @param string $class HTML class before sanitization.
* @param string $fallback The fallback string.
*/
return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


