php中数组编码转换的方法

WBOY
Release: 2016-07-25 08:58:57
Original
1082 people have browsed it
  1. unserialize(iconv('gbk','utf-8',serialize($array)));
复制代码

结果是空白的。

借助var_export函数,最终函数如下:

  1. function array_iconv($in_charset,$out_charset,$arr){
  2. return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));
  3. }
复制代码

原理分析: var_export函数中,设置第二个参数为true,返回数组原型字符串,将字符串转换为utf-8编码,之后再用eval来执行返回(类似匿名函数?)。 如此便轻松解决了php中数组编码转换的问题了。



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!