Home >Backend Development >PHP Problem >How to solve the garbled problem of php access

How to solve the garbled problem of php access

藏色散人
藏色散人Original
2020-08-01 10:53:453030browse

Solution to php access garbled code: 1. Use iconv function to create a transcoding custom function from GBK to "UTF-8"; 2. Create a transcoding function from "UTF-8" to GBK Function, the statement is "dec($c){return iconv(...)).

How to solve the garbled problem of php access

## Recommended: "

PHP Video Tutorial

Solution to the garbled problem of PHP using UTF8 encoding to read ACCESS

PHP paired with ACCESS is a very cold topic, but it has a lot of practicality, especially Programmers who have transferred from ASP have a special understanding of ACCESS. Xuewen Training will also talk about the system development of ACCESS with PHP in actual PHP training. So today we will share what PHP ACCESS usually does in actual development. Solution to the UTF-8 encoding problem encountered.

How does the garbled problem occur when PHP uses UTF8 encoding to read the ACCESS database?

First of all, PHP is an international programming language. We usually use UTF-8 encoding when using it. If it is used with a MYSQL database and is set to UTF-8 encoding in the MYSQL database, there will be no problems when reading.

Secondly, ACCESS is a A small local database developed by Microsoft, which uses the local system encoding by default. The Simplified Chinese system uses GBK encoding. And this encoding type cannot be changed.

So the problem arises!! UTF-8 PHP reads GBK's ACCESS, and garbled characters will appear when the data is displayed on the page.

Of course, don't worry if you encounter this problem, it will not damage the database when the data is not written. Data. The next step is how to solve this problem. The solution is as follows:

1. Use the iconv function to make a custom transcoding function from GBK to UTF-8, such as the following code:

function enc($c){return iconv('gbk','utf-8',$c);}

2. In order to write the encoding to the database to meet the needs of the database, we also need to make a function to convert from UTF-8 to GBK:

function dec($c){return iconv('utf-8','gb2312',$c);}

After making the transcoding function, the next step is normal Used. Use the enc() function when transferring data from the database to display on the page, and use the dec() function when submitting data from the page to the database. This can solve the problem of PHP using UTF-8 encoding and ACCESS using the system. There is a problem with the default encoding.

The above is the detailed content of How to solve the garbled problem of php access. For more information, please follow other related articles on the PHP Chinese website!

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