Title: wp_is_valid_utf8
Published: February 24, 2026
Last modified: August 20, 2026

---

# wp_is_valid_utf8( string $bytes ): bool

## In this article

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

Determines if a given byte string represents a valid UTF-8 encoding.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_is_valid_utf8/?output_format=md#description)󠁿

Note that it’s unlikely for non-UTF-8 data to validate as UTF-8, but it is still
possible. Many texts are simultaneously valid UTF-8, valid US-ASCII, and valid ISO-
8859-1 (`latin1`).

Example:

    ```php
    true === wp_is_valid_utf8( '' );
    true === wp_is_valid_utf8( 'just a test' );
    true === wp_is_valid_utf8( "\xE2\x9C\x8F" );    // Pencil, U+270F.
    true === wp_is_valid_utf8( "\u{270F}" );        // Pencil, U+270F.
    true === wp_is_valid_utf8( '✏' );              // Pencil, U+270F.

    false === wp_is_valid_utf8( "just xC0 test" ); // Invalid bytes.
    false === wp_is_valid_utf8( "\xE2\x9C" );       // Invalid/incomplete sequences.
    false === wp_is_valid_utf8( "\xC1\xBF" );       // Overlong sequences.
    false === wp_is_valid_utf8( "\xED\xB0\x80" );   // Surrogate halves.
    false === wp_is_valid_utf8( "B\xFCch" );        // ISO-8859-1 high-bytes.
                                                    // E.g. The “ü” in ISO-8859-1 is a single byte 0xFC,
                                                    // but in UTF-8 is the two-byte sequence 0xC3 0xBC.
    ```

A “valid” string consists of “well-formed UTF-8 code unit sequence[s],” meaning 
that the bytes conform to the UTF-8 encoding scheme, all characters use the minimal
byte sequence required by UTF-8, and that no sequence encodes a UTF-16 surrogate
code point or any character above the representable range.

### 󠀁[See also](https://developer.wordpress.org/reference/functions/wp_is_valid_utf8/?output_format=md#see-also)󠁿

 * [https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-3/#G32860](https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-3/#G32860/)

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

 `$bytes`stringrequired

String which might contain text encoded as UTF-8.

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

 bool Whether the provided bytes can decode as valid UTF-8.

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

    ```php
    function wp_is_valid_utf8( string $bytes ): bool {
    	return mb_check_encoding( $bytes, 'UTF-8' );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/utf8.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/utf8.php#L39)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/utf8.php#L39-L41)

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

| Used by | Description | 
| [wxr_cdata()](https://developer.wordpress.org/reference/functions/wxr_cdata/)`wp-admin/includes/export.php` |

Wraps given string in XML CDATA tag.

  | 
| [wp_read_image_metadata()](https://developer.wordpress.org/reference/functions/wp_read_image_metadata/)`wp-admin/includes/image.php` |

Gets extended image metadata, exif or iptc as available.

  | 
| [sanitize_file_name()](https://developer.wordpress.org/reference/functions/sanitize_file_name/)`wp-includes/formatting.php` |

Sanitizes a filename, replacing whitespace with dashes.

  | 
| [sanitize_title_with_dashes()](https://developer.wordpress.org/reference/functions/sanitize_title_with_dashes/)`wp-includes/formatting.php` |

Sanitizes a title, replacing whitespace and a few other characters with dashes.

  | 
| [wp_check_invalid_utf8()](https://developer.wordpress.org/reference/functions/wp_check_invalid_utf8/)`wp-includes/formatting.php` |

Checks for invalid UTF8 in a string.

  | 
| [remove_accents()](https://developer.wordpress.org/reference/functions/remove_accents/)`wp-includes/formatting.php` |

Converts all accent characters to ASCII characters.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_is_valid_utf8/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_is_valid_utf8/?output_format=md#)

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

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

## User Contributed Notes

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