PHP数组编码转换实例演示_PHP教程

WBOY
Release: 2016-07-13 10:39:56
Original
925 people have browsed it

   用构建数组原型的序列化方法,借助var_export函数,最终函数如下:

 代码如下  

function array_iconv($in_charset,$out_charset,$arr){

return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));

}

  原理很简单 var_export设置第二个参数为true,返回数组原型字符串,将字符串转换为utf-8编码,之后再用eval来执行返回(类似匿名函数?),至此完美解决问题。

  一聚教程小编还有一个想法,就是利用foreach遍历数组然后再利用iocnv函数起先一个个转换了,不过这样转换的是把数组值进行转换了。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/727589.htmlTechArticle用构建数组原型的序列化方法,借助var_export函数,最终函数如下: 代码如下 function array_iconv($in_charset,$out_charset,$arr){ return eval('return '.iconv($...
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!