utf8_encode()
utf8_encode() — Converts a string from ISO-8859-1 to UTF-8.
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 ISO-8859-1 encoding to UTF-8.
Signature
utf8_encode(string $string): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | An ISO-8859-1 string. |
Return value
Returns the UTF-8 translation of string.
Example
A runnable snippet:
// Convert the string 'Zoƫ' from ISO 8859-1 to UTF-8 $iso8859_1_string = "\x5A\x6F\xEB"; $utf8_string = utf8_encode($iso8859_1_string); echo bin2hex($utf8_string), "\n";
Output:
5a6fc3ab
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_decode(), mb_convert_encoding(), iconv()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page utf8_encode() (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.