WP_HTML_Processor::get_encoding
Gets an encoding from a given string.
This is an algorithm defined in the WHAT-WG specification.
Example:
'UTF-8' === self::get_encoding( 'utf8' ); 'UTF-8' === self::get_encoding( " \tUTF-8 " ); null === self::get_encoding( 'UTF-7' ); null === self::get_encoding( 'utf8; charset=' );
Method of the class: WP_HTML_Processor{}
No Hooks.
Returns
String|null. Known encoding if matched, otherwise null.
Usage
$result = WP_HTML_Processor::get_encoding( $label ): ?string;
- $label(string) (required)
- A string which may specify a known encoding.
Notes
Changelog
| Since 6.7.0 | Introduced. |
WP_HTML_Processor::get_encoding() WP HTML Processor::get encoding code WP 6.9
protected static function get_encoding( string $label ): ?string {
/*
* > Remove any leading and trailing ASCII whitespace from label.
*/
$label = trim( $label, " \t\f\r\n" );
/*
* > If label is an ASCII case-insensitive match for any of the labels listed in the
* > table below, then return the corresponding encoding; otherwise return failure.
*/
switch ( strtolower( $label ) ) {
case 'unicode-1-1-utf-8':
case 'unicode11utf8':
case 'unicode20utf8':
case 'utf-8':
case 'utf8':
case 'x-unicode20utf8':
return 'UTF-8';
default:
return null;
}
}