Definition:
function sanitize_html_class( $class, $fallback = '' ) {}
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.
Parameters
- string $class: The classname to be sanitized
- string $fallback: Optional. The value to return if the sanitization end’s up as an empty string. Defaults to an empty string.
Return values
returns:The sanitized value
Defined filters
- sanitize_html_class
apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback )
Source code
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 );
}
2773

February 12, 2011 


No comments yet... Be the first to leave a reply!