Home  >  Article  >  Backend Development  >  What to do if php adds access garbled characters

What to do if php adds access garbled characters

藏色散人
藏色散人Original
2022-10-20 10:18:251139browse

Solution to php adding access garbled characters: 1. Use "function enc($c){return iconv('gbk','utf-8',$c);}" to create a transfer from GBK UTF-8 function; 2. Use "function dec($c){return iconv('utf-8','gb2312',$c);}" to create a function that converts from UTF-8 to GBK.

What to do if php adds access garbled characters

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if I add access garbled characters to php?

Solution to garbled characters when PHP reads Access database

The Chinese version of access defaults to GBK format, and the character type cannot be changed, so use When php reads it, it will be garbled.

The solution is: use iconv conversion

1. Use the iconv function to create 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 from UTF-8 to GBK:

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

After making the transcoding function, the next step is to use it normally. . 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 default encoding. Problem.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php adds access garbled characters. 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