Php solves database garbled characters _ PHP Tutorial

Source: Internet
Author: User
Php solves the database garbled problem. If the database uses UTF-8, what encoding is your text? Use mb_convert_encoding or iconv to convert the encoding. The two codes must be consistent to avoid garbled characters. And if the database is using UTF-8, what encoding is your text?

Use mb_convert_encoding or iconv to convert the encoding. The two codes must be consistent to avoid garbled characters. There is also the database connection. if you add set names, all the connections should be added in that way. otherwise, garbled characters will be displayed.

If the following example does not undergo encoding conversion, the problem may occur.

$ FileName = "qtgz/qtgongzi.txt ";
$ FContent = file ($ fileName );
// Pay the value of the current element to $ a_content list and pay the value of the array element to some variables.
Foreach ($ fContent as $ a_content ){
List ($ QT_sfz, $ QT_xm, $ QT_bz, $ QT_je) = explode (",", $ a_content );
If ($ QT_sfz! = "" And $ QT_xm! = "" And $ QT_bz! = "" And $ QT_je! = ""){
Echo $ QT_xm;
// Insert the acquired time to the database
$ QT_sj = date ("Ym ");
$ Query = "insert into qita (QT_sfz, QT_xm, QT_bz, QT_je, QT_beizhu, QT_sj) values ('$ QT_sfz', '$ QT_xm', '$ QT_bz ', '$ QT_je', '$ QT_beizhu', '$ QT_sj ')";
// Echo $ query;
$ Rst = $ aa-> excu ($ query );

Why? Use mb_convert_encoding or iconv to convert the encoding. The two codes must be consistent to avoid garbled characters. And...

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.