我的网站页面 90% 使用 utf8 编码功能来编译 DataTable。
$a[] = array_map('utf8_encode', $item);
使用旧版本的 php 8.0 一切都很好,在新版本中,当 $item 的值($item 是一个数组)为空时,它会给我一个错误。
什么是有效的替代方案?
我们知道utf8_encode
自 PHP 8.2.0 起已弃用,并将在 PHP 9 中删除https://php.watch/versions/8.2/utf8_encode-utf8_decode-已弃用 https://php.watch/versions/8.2/utf8_encode-utf8_decode-deprecated
所以替代方案可以是:
$oldSample = ["\x5A\x6F\xEB"];
$result= array_map
(
function ($item){
return mb_convert_encoding($item, "UTF-8", mb_detect_encoding($item));
},
$oldSample
);
var_dump($result);
文档:
-
https://www.php.net/manual/en/function.mb-convert-encoding.php https://www.php.net/manual/en/function.mb-convert-encoding.php
https://www.php.net/manual/de/function.mb-detect-encoding.php https://www.php.net/manual/de/function.mb-detect-encoding.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)