Home  >  Article  >  Backend Development  >  How to convert php array to utf8

How to convert php array to utf8

藏色散人
藏色散人Original
2021-09-17 11:29:472247browse

php数组转utf8的方法:1、使用iconv方法转换;2、通过“mb_convert_encoding()”方法转换;3、结合“eval()”和“var_export()”方法转换。

How to convert php array to utf8

本文操作环境:Windows7系统、PHP7.1版,Dell G3电脑

php数组怎么转utf8?

php数组gbk和utf8的相互转化

GBK转换成UFT-8

用iconv()转化效率没有mb_convert_encoding()效率高:

$str = iconv("gbk", "utf-8//ignore", $str);
或者:
$str = mb_convert_encoding($str, "utf-8", "gbk");

eval() var_export() 把数组整体转化,如有一些特殊字符的话,可以用str_replace()进行转化

$arr=eval('return '.iconv('gbk',"utf-8",var_export($arr,true).';'));
$arr= eval('return ' . mb_convert_encoding(str_replace("' . \"\\0\" . '", '', var_export($arr, true)) .';',"utf-8","gbk"));//gbk转码utf8

 推荐学习:《PHP视频教程

The above is the detailed content of How to convert php array to utf8. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn