PHP encoding conversion analysis

怪我咯
Release: 2023-03-13 15:48:02
Original
1524 people have browsed it

When the

phpoutputted stringencoding is inconsistent with the encoding declared in the header header information, garbled characters are output.

In PHP program development, encoding problems must have troubled many people. For example: when we need to output a GBK-encoded string, we don’t know whether the passed string is GBK-encoded or UTF8-encoded, so we cannot To convert the encoding, we need a function that can unify the encoding.

Use PHP to connect to the MS SQL Server database and check the encoding of the database

SELECT COLLATIONPROPERTY('Chinese_PRC_Stroke_CI_AI_KS_WS', 'CodePage')
Copy after login

The return value is 936, which is GBK encoding.

936 Simplified Chinese GBK
950 Traditional Chinese BIG5
437 American/Canadian English
932 Japanese
949 Korean
866 Russian
65001 unicode UFT-8

If the field has Chinese characters and the PHP file setting encoding is GBK2312, there will be no problem when fetching the database information:

print_r($rs[ "Customer encoding"]);

If the PHP file setting encoding is utf-8, an error will be reported.

If you have to set the encoding of the PHP file to utf-8, you need to convert the encoding:

print_r($rs[mb_convert_encoding("Customer encoding","GBK","UTF -8")]);//Print record Array

This way there will be no problem.

The above is the detailed content of PHP encoding conversion analysis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template