W3docs

How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?

In PHP, you can use the utf8_decode() function to decode a string that contains Unicode escape sequences.

In PHP, double-quoted strings do not natively interpret \uXXXX escape sequences, so the string contains a literal backslash followed by u. To convert a string containing these literal sequences into proper UTF-8 characters, you can use the json_decode() function as a workaround.

Here's an example:

Example of using the json_decode() function to decode a string that contains Unicode escape sequences in PHP

php— editable, runs on the server

This workaround relies on json_decode() expecting valid JSON syntax, which is why the string is wrapped in double quotes. The function correctly interprets \uXXXX sequences and returns the proper UTF-8 encoded character. For PHP 7.3+, you can pass the JSON_THROW_ON_ERROR flag to automatically throw a JsonException on failure, simplifying error handling.