utf8_decode()
utf8_decode() — Converts a string from UTF-8 to ISO-8859-1, replacing invalid or unrepresentable characters.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
The PHP manual marks this function as deprecated (since PHP 8.2, visit the php.net documentation for various alternatives): do not use it in new code.
What it does
This function converts the string string from the UTF-8 encoding to ISO-8859-1. Bytes in the string which are not valid UTF-8, and UTF-8 characters which do not exist in ISO-8859-1 (that is, code points above U+00FF) are replaced with ?.
Signature
utf8_decode(string $string): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | A UTF-8 encoded string. |
Return value
Returns the ISO-8859-1 translation of string.
Example
A runnable snippet:
// Convert the string 'Zoë' from UTF-8 to ISO 8859-1 $utf8_string = "\x5A\x6F\xC3\xAB"; $iso8859_1_string = utf8_decode($utf8_string); echo bin2hex($iso8859_1_string), "\n"; // Invalid UTF-8 sequences are replaced with '?' $invalid_utf8_string = "\xC3"; $iso8859_1_string = utf8_decode($invalid_utf8_string); var_dump($iso8859_1_string); // Characters which don't exist in ISO 8859-1, such as // '€' (Euro Sign) are also replaced with '?' $utf8_string = "\xE2\x82\xAC"; $iso8859_1_string = utf8_decode($utf8_string); var_dump($iso8859_1_string);
Output:
5a6feb string(1) "?" string(1) "?"
Changelog
| Version | Change |
|---|---|
| 8.2.0 | This function has been deprecated. |
| 7.2.0 | This function has been moved from the XML extension to the core of PHP. In previous versions, it was only available if the XML extension was installed. |
See also
utf8_encode(), mb_convert_encoding(), iconv()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page utf8_decode() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.