We know that utf8_encode is deprecated since PHP 8.2.0 and will be removed in PHP 9 https://php.watch/versions/8.2/utf8_encode-utf8_decode-deprecated

So the alternative can be:

$oldSample = ["\x5A\x6F\xEB"];
$result= array_map
(
    function ($item){
        return mb_convert_encoding($item, "UTF-8", mb_detect_encoding($item));
    }, 
    $oldSample
);
var_dump($result);

Documentation:

  • https://www.php.net/manual/en/function.mb-convert-encoding.php
  • https://www.php.net/manual/en/function.mb-detect-encoding.php
Answer from Eugene Kaurov on Stack Overflow
🌐
PHP
php.net › manual › en › function.utf8-decode.php
PHP: utf8_decode - Manual
PHP 8.5.9 Released! ... utf8_decode — Converts a string from UTF-8 to ISO-8859-1, replacing invalid or unrepresentable characters
🌐
PHP.Watch
php.watch › versions › 8.2 › utf8_encode-utf8_decode-deprecated
`utf8_encode` and `utf8_decode` functions deprecated - PHP 8.2 • PHP.Watch
Function uft8_decode() is deprecated in ... on line ... utf8_encode function encodes a ISO-8859-1 encoded string text into UTF-8. Most of the utf8_encode calls in legacy PHP applications use this function as an additional safe-guard to prevent any potential malformed text to UTF-8, but as shown in the examples above, using this function often results in undesired outcomes rather than fixing any malformed text.
🌐
W3Schools
w3schools.com › php › func_xml_utf8_decode.asp
PHP utf8_decode() Function
The utf8_decode() function decodes a UTF-8 string to ISO-8859-1. Note: This function was deprecated in PHP 8.2.0.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-utf8_decode-function
PHP | utf8_decode() Function - GeeksforGeeks
January 6, 2023 - The utf8_decode() function is an inbuilt function in PHP which is used to decode a UTF-8 string to the ISO-8859-1.
🌐
OnlinePHP
onlinephp.io › utf8-decode
utf8_decode - Online Tool
PHP Functions · String Manipulation · utf8_decode · Execute utf8_decode with this online tool utf8_decode() - Converts a string from UTF-8 to ISO-8859-1, replacing invalid or unrepresentable characters · Utf8 Decode Online Tool · Manual ...
🌐
PHP
wiki.php.net › rfc › remove_utf8_decode_and_utf8_encode
PHP: rfc:remove_utf8_decode_and_utf8_encode
April 4, 2022 - Passing any string of bytes to utf8_encode produces a valid UTF-8 string; and the original bytes can be recovered using utf8_decode. This makes it possible to “armour” arbitrary binary data for transmission or storage as UTF-8 strings, similar to how Base64 or quoted printable encoding ...
🌐
W3docs
w3docs.com › learn-php › utf8-decode.html
utf8_decode() | W3Docs
The utf8_decode() function is a PHP built-in function that converts a string with UTF-8 encoding to ISO-8859-1 encoding. UTF-8 is a popular character encoding
🌐
mixable Blog
mixable.blog › home › php: function utf8_decode() and utf8_encode() have been deprecated
PHP: utf8_decode() and utf8_encode() have been deprecated | mixable Blog
May 29, 2024 - The utf8_encode() and utf8_decode() functions in PHP are used for encoding and decoding strings between ISO-8859-1 (Latin-1) and UTF-8.
Find elsewhere
🌐
GitHub
github.com › php › doc-en › blob › master › reference › strings › functions › utf8-decode.xml
doc-en/reference/strings/functions/utf8-decode.xml at master · php/doc-en
<?php · // 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); ·
Author   php
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-utf8_encode-function
PHP utf8_encode() Function - GeeksforGeeks
September 27, 2024 - The utf8_encode() function in PHP converts ISO-8859-1 (Latin-1) encoded strings to UTF-8 encoding.
🌐
OnlinePHP
onlinephp.io › utf8-decode › manual
utf8_decode - OnlinePHP.io Example
utf8_decode - Converts a string from UTF-8 to ISO-8859-1, replacing invalid or unrepresentable characters
🌐
MojoAuth
mojoauth.com › character-encoding-decoding › utf-8-encoding--php
UTF-8 Encoding : PHP | Encoding Solutions Across Programming Languages
<?php // Original string in ISO-8859-1 encoding $originalString = "Hello, world!"; // Convert to UTF-8 $utf8String = mb_convert_encoding($originalString, 'UTF-8', 'ISO-8859-1'); // Output the UTF-8 encoded string echo $utf8String; // Outputs: Hello, world! ?> This snippet demonstrates how to convert a string from ISO-8859-1 to UTF-8 encoding. Using functions like mb_convert_encoding() ensures that your application correctly handles various character sets. Decoding UTF-8 strings in PHP is equally simple.
🌐
W3cubDocs
docs.w3cub.com › php › function.utf8-decode
Utf8_decode - PHP - W3cubDocs
(PHP 4, PHP 5, PHP 7) utf8_decode — Converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte ISO-8859-1 · utf8_decode ( string $data ) : string · This function converts the string data from the UTF-8 encoding to ISO-8859-1. Bytes in the string which are not valid UTF-8, ...
🌐
W3Schools
w3schools.com › php › func_xml_utf8_encode.asp
PHP utf8_encode() Function
boolval() debug_zval_dump() doubleval() is_countable() empty() floatval() get_defined_vars() get_resource_type() gettype() intval() is_array() is_bool() is_callable() is_double() is_float() is_int() is_integer() is_iterable() is_long() is_null() is_numeric() is_object() is_real() is_resource() is_scalar() is_string() isset() print_r() serialize() settype() strval() unserialize() unset() var_dump() var_export() PHP XML Parser · utf8_decode() utf8_encode() xml_error_string() xml_get_current_byte_index() xml_get_current_column_number() xml_get_current_line_number() xml_get_error_code() xml_parse