Title: WP_HTML_Decoder::code_point_to_utf8_bytes
Published: July 16, 2024
Last modified: August 20, 2026

---

# WP_HTML_Decoder::code_point_to_utf8_bytes( int $code_point ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#changelog)

Encode a code point number into the UTF-8 encoding.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#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:

    ```php
    '🅰' === 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://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#see-also)󠁿

 * [https://www.rfc-editor.org/rfc/rfc3629](https://www.rfc-editor.org/rfc/rfc3629/):
   For the UTF-8 standard.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#parameters)󠁿

 `$code_point`intrequired

Which code point to convert.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#return)󠁿

 string Converted code point, or `�` if invalid.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#source)󠁿

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

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/html-api/class-wp-html-decoder.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/html-api/class-wp-html-decoder.php#L502)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/html-api/class-wp-html-decoder.php#L502-L506)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_HTML_Decoder::read_character_reference()](https://developer.wordpress.org/reference/classes/wp_html_decoder/read_character_reference/)`wp-includes/html-api/class-wp-html-decoder.php` |

Attempt to read a character reference at the given location in a given string, depending on the context in which it’s found.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_html_decoder/code_point_to_utf8_bytes/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_html_decoder%2Fcode_point_to_utf8_bytes%2F)
before being able to contribute a note or feedback.