Home  >  Article  >  Backend Development  >  Example of php array encoding conversion function_PHP tutorial

Example of php array encoding conversion function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:35:50956browse

Scenario description/problem description:

The Ajax submission page encoding is gb2312 and the database encoding is utf8. Insert data without changing the page and database encoding.

Custom function:

        return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));   
 代码如下

Function description:
var_export sets the second parameter to true, returns the array prototype string, converts the string to utf-8 encoding, and then uses eval to perform the return.

Example:

$data = array_iconv('gb2312','utf-8',$postdata)
print_r($data);
The code is as follows
 代码如下
$data = array_iconv('gb2312','utf-8',$postdata)

print_r($data); td>

With the Firefox firebug component we can see:

Example of php array encoding conversion function_PHP tutorial

Look at the database again:

Example of php array encoding conversion function_PHP tutorial

You can see that the encoding is normal and the storage is successful
    ​ Articles you may be interested in
  • PHP array encoding conversion example demonstration
  • Solving the problem of Chinese character encoding in xml files generated from php array
  • Loop implementation (string, object, or array) encoding and mutual conversion in php

http://www.bkjia.com/PHPjc/741658.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/741658.htmlTechArticleScenario description/problem description: Ajax submission page encoding is gb2312, database encoding is utf8, the page and database will not be changed Insert data without encoding. Custom function: The code is as follows...
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