PHP uses UTF8 encoding to read the garbled problem solution for access (GO)

Source: Internet
Author: User

PHP uses UTF8 encoding to read the garbled problem solution for access

http://it.xwstudy.com/readnews.php?id=627

Source: Site Edit Release Date: 2013-05-27 There are 1790 people who viewed this information

PHP with Access is a very cold topic, but there are many practical, especially from the ASP to the programmer, Access has a special understanding. The training in the actual PHP training will also talk about access in conjunction with PHP system development. Well, let's share it today. Php+access's solution to the UTF-8 coding problem that is commonly encountered in combat development .

How does PHP read the garbled problem of an Access database using UTF8 encoding ?

First of all, PHP is an international programming language, and we usually use UTF-8 encoding when we use it. If you are paired with a MySQL database and set the UTF-8 encoding in the MySQL database, there will be no problem reading.

Second, access is a small local database developed by Microsoft, using the system code that is local by default, and the Simplified Chinese system uses GBK encoding. And this type of encoding is immutable.

So the problem arises!! UTF-8 PHP reads the GBK access and displays the data on the page with garbled characters.

Of course, there is no need to worry about this problem, and the data in the database is not corrupted when the data is not written. The next step is how to solve this problem, the solution is as follows:

First, use the Iconv function to make a transcoding custom function from GBK to UTF-8 , such as the following code:

Function Enc ($c) {return iconv (' GBK ', ' utf-8 ', $c);}

Second, in order to write the database encoding is to meet the needs of the database, so we also want to make a shift from UTF-8 to GBK function:

function Dec ($c) {return iconv (' Utf-8 ', ' gb2312 ', $c);}

The transcoding function is made, and then it is used normally. Using the ENC () function when data from the database is displayed on the page, the DEC () function is used to submit data from the page to the database, which can be a good solution to PHP's use of UTF-8 encoding, and Access uses the system default encoding problem.

PHP uses UTF8 encoding to read the garbled problem solution for access (GO)

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.