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:
The code is as follows | |
代码如下 | |
$data = array_iconv('gb2312','utf-8',$postdata) |
print_r($data); td>
With the Firefox firebug component we can see:
Look at the database again:
You can see that the encoding is normal and the storage is successful