utf8_encode
Converts a string from ISO-8859-1 to UTF-8
&warn.deprecated.function-8-2-0;
&reftitle.description;
#[\Deprecated]
stringutf8_encode
stringstring
This function converts the string string from the
ISO-8859-1 encoding to UTF-8.
This function does not attempt to guess the current encoding of the provided
string, it assumes it is encoded as ISO-8859-1 (also known as "Latin 1")
and converts to UTF-8. Since every sequence of bytes is a valid ISO-8859-1
string, this never results in an error, but will not result in a useful string
if a different encoding was intended.
Many web pages marked as using the ISO-8859-1 character
encoding actually use the similar Windows-1252 encoding,
and web browsers will interpret ISO-8859-1 web pages as
Windows-1252. Windows-1252 features
additional printable characters, such as the Euro sign
(€) and curly quotes (“
”), instead of certain ISO-8859-1
control characters. This function will not convert such
Windows-1252 characters correctly. Use a different
function if Windows-1252 conversion is required.
&reftitle.parameters;
string
An ISO-8859-1 string.
&reftitle.returnvalues;
Returns the UTF-8 translation of string.
&reftitle.changelog;
&Version;
&Description;
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.
&reftitle.examples;
Basic example
]]>
&example.outputs;
&reftitle.notes;
Deprecation and alternatives
This function is deprecated as of PHP 8.2.0,
and will be removed in a future version. Existing uses should be checked
and replaced with appropriate alternatives.
Similar functionality can be achieved with mb_convert_encoding,
which supports ISO-8859-1 and many other character encodings.
]]>
&example.outputs;
Other options which may be available depending on the extensions installed are
UConverter::transcode and iconv.
The following all give the same result:
]]>
&example.outputs;
&reftitle.seealso;
utf8_decode
mb_convert_encoding
UConverter::transcode
iconv