Encode a code point number into the UTF-8 encoding.
Description
This encoder implements the UTF-8 encoding algorithm for converting a code point into a byte sequence. If it receives an invalid code point it will return the Unicode Replacement Character U+FFFD �.
Example:
'🅰' === WP_HTML_Decoder::code_point_to_utf8_bytes( 0x1f170 );
// Half of a surrogate pair is an invalid code point.
'�' === WP_HTML_Decoder::code_point_to_utf8_bytes( 0xd83c );
See also
- https://www.rfc-editor.org/rfc/rfc3629: For the UTF-8 standard.
Parameters
$code_pointintrequired- Which code point to convert.
Source
public static function code_point_to_utf8_bytes( $code_point ): string {
$string = mb_chr( $code_point, 'UTF-8' );
return false !== $string ? $string : '�';
}
Changelog
| Version | Description |
|---|---|
| 6.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.