PHP.nl

utf8_encode

utf8_encode

Converts a string from ISO-8859-1 to UTF-8

string **utf8_encode** string $string

This function converts the string from the encoding to . string``ISO-8859-1``UTF-8

Opmerking: > 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  character
encoding actually use the similar  encoding,
and web browsers will interpret  web pages as
.  features
additional printable characters, such as the Euro sign
() and curly quotes (
), instead of certain 
control characters. This function will not convert such
 characters correctly. Use a different
function if  conversion is required.

ISO-8859-1``Windows-1252``ISO-8859-1``Windows-1252``Windows-1252``€``“``”``ISO-8859-1``Windows-1252``Windows-1252

stringAn ISO-8859-1 string.

Returns the UTF-8 translation of . string

Voorbeeld: Basic example

<?php
// 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";
?>
5a6fc3ab

Opmerking: > ### Deprecation and alternatives

This function is  as of PHP 8.2.0,
and will be removed in a future version. Existing uses should be checked
and replaced with appropriate alternatives.

deprecated

Similar functionality can be achieved with ,
which supports ISO-8859-1 and many other character encodings.

`mb_convert_encoding````php


```php
c3ab
cebb
e282ac
Other options which may be available depending on the extensions installed are
 and .

UConverter::transcode``iconv

The following all give the same result:
<?php
$iso8859_1_string = "\x5A\x6F\xEB"; // 'Zoë' in ISO-8859-1

$utf8_string = utf8_encode($iso8859_1_string);
echo bin2hex($utf8_string), "\n";

$utf8_string = mb_convert_encoding($iso8859_1_string, 'UTF-8', 'ISO-8859-1');
echo bin2hex($utf8_string), "\n";

$utf8_string = UConverter::transcode($iso8859_1_string, 'UTF8', 'ISO-8859-1');
echo bin2hex($utf8_string), "\n";

$utf8_string = iconv('ISO-8859-1', 'UTF-8', $iso8859_1_string);
echo bin2hex($utf8_string), "\n";
?>
5a6fc3ab
5a6fc3ab
5a6fc3ab
5a6fc3ab

utf8_decode``mb_convert_encoding``UConverter::transcode``iconv