Functions utf8_encode and utf8_decode are Deprecated in PHP 8.2

utf8_encode and utf8_decode functions, despite their names, are used to convert strings between ISO-8859-1 (Also known as "Latin 1") and UTF-8 encodings. These functions do not attempt to detect the actual character encoding in a given text, and always convert character encodings between ISO-8859-1 and UTF-8, even if the source text is not encoded in ISO-8859-1.

Although PHP includes utf8_encode and utf8_decode functions in its standard library, these functions cannot be used to detect and convert other character encodings such as Windows-1252, UTF-16, and UTF-32 to UTF-8. Passing arbitrary text to utf8_encode function is prone to bugs that do not result in any warnings or errors but may lead to undesired results.

Because of the misleading function names, lack of error messages and warnings, and the lack of support for character encodings other than ISO-8859-1, utf8_encode and utf8_decode functions are deprecated in PHP 8.2.

<?php

$utf8 = utf8_encode("\xa5\xa7\xb5"); // ISO-8859-1 -> UTF-8
$iso88591 = utf8_decode($utf8);      // UTF-8 -> ISO-8859-1

Deprecated: Function utf8_encode() is deprecated in main.php on line 3
Deprecated: Function utf8_decode() is deprecated in main.php on line 4

Better replacement is to use syntax:

<?php

$utf8 = mb_convert_encoding("\xa5\xa7\xb5", 'UTF-8', 'ISO-8859-1'); // ISO-8859-1 -> UTF-8
$iso88591 = mb_convert_encoding($utf8, 'ISO-8859-1', 'UTF-8');      // UTF-8 -> ISO-8859-1
Share with Me via Nextcloud