How to convert array encoding in php

WBOY
Release: 2016-07-25 08:58:57
Original
1203 people have browsed it
  1. unserialize(iconv('gbk','utf-8',serialize($array)));
Copy the code

The result is blank.

With the help of var_export function, the final function is as follows:

  1. function array_iconv($in_charset,$out_charset,$arr){
  2. return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));
  3. }
Copy code

Principle analysis: In the var_export function, set the second parameter to true, return the array prototype string, convert the string to utf-8 encoding, and then use eval to perform the return (similar to an anonymous function?). This easily solves the problem of array encoding conversion in 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