PHP array Encoding conversion function Example _php Tutorial

Source: Internet
Author: User
Scenario Description/Problem Description:

The Ajax commit page is encoded as gb2312, the database is encoded as UTF8, and the data is inserted without changing the page and database encoding.

Custom functions:



< td=""> Return eval (' Return '. Iconv ($in _charset, $out _charset,var_export ($arr, true). '; '); }
The code is as follows

Function Description:
Var_export sets the second argument to True, returns the array prototype string, converts the string to Utf-8 encoding, and then uses Eval to perform the return.

Example:


< td=""> $data = Array_iconv (' gb2312 ', ' utf-8 ', $postdata) Print_r ($data);
The code is as follows

With the help of the Firefox Firebug component we can see:

Then look at the database:

You can see that the encoding is OK and the storage is successful

Articles you may be interested in
    • PHP array Encoding Conversion example Demo
    • Solve the problem of generating XML files Chinese character coding php array arrays
    • Cyclic implementations in PHP (strings, objects, or arrays) encode each other

http://www.bkjia.com/PHPjc/741658.html www.bkjia.com true http://www.bkjia.com/PHPjc/741658.html techarticle Scenario Description/Problem Description: The AJAX submission page is encoded as gb2312, the database is encoded as UTF8, and the data is inserted without changing the page and database encoding. Custom functions: The code is as follows ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.