WP_HTML_Decoder::code_point_to_utf8_bytes( int $code_point ): string

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

Parameters

$code_pointintrequired
Which code point to convert.

Return

string Converted code point, or if invalid.

Source

public static function code_point_to_utf8_bytes( $code_point ): string {
	$string = mb_chr( $code_point, 'UTF-8' );

	return false !== $string ? $string : '�';
}

Changelog

VersionDescription
6.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.