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
🌐
W3Schools
w3schools.com › Php › func_xml_utf8_decode.asp
PHP utf8_decode() Function
<?php $text = "\xE0"; echo utf8_encode($text) ."<br>"; echo utf8_decode($text); ?> Try it Yourself »
🌐
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.
🌐
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
🌐
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: ...
🌐
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
🌐
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.
🌐
Toptal
toptal.com › php › a-utf-8-primer-for-php-and-mysql
A Guide to UTF-8 Encoding in PHP and MySQL | Toptal®
January 16, 2026 - A useful function for doing this (which I found here) is the following: function utf8_for_xml($string) { return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string); }
🌐
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
🌐
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
🌐
Canopas
canopas.com › php-useful-encoding-and-decoding-functions-you-need-to-know-210e523a065f
PHP: Useful Encoding and decoding Functions You Need to Know
May 18, 2022 - <?php $text = "\xE0"; echo utf8_encode($text); # output : à ?> This function is used to decode a UTF-8 string to ISO-8859–1.
🌐
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, ...