Santizes a 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.
Signature
sanitize_html_class( $class, $fallback = '' )
- class
- (string) The classname to be sanitized
- fallback
- (string) Optional. The value to return if the sanitization end's up as an empty string. Defaults to an empty string.
Default:''
Return
(string) The sanitized value
Source
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 )
$sanitized = $fallback;
return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );
}
WP Trac GitHub Bitbucket
Link here
-
URL
http://queryposts.com/function/sanitize_html_class/ -
HTML
<a href='http://queryposts.com/function/sanitize_html_class/'>sanitize_html_class()</a> -
Markdown
[sanitize_html_class()](http://queryposts.com/function/sanitize_html_class/) -
BBCode
[url=http://queryposts.com/function/sanitize_html_class/]sanitize_html_class()[/url]