90% of my website pages use the UTF-8 encoding feature to compile a DataTable.
$a[] = array_map('utf8_encode', $item);
With the old version 8.0 of PHP, everything was fine; however, in the new version, it tells me that this function is deprecated.
What is a valid alternative?
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With