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)