PHP read MySQL data to page garbled

Source: Internet
Author: User

Garbled, there is garbled in the database, page extraction data garbled and other display normal, phpMyAdmin also show normal, and so on.

Database, Web page encoding inconsistency caused the assumption that using Utf-8 encoding (your uploaded php file using utf-8 encoding) to connect to the database with mysql_query ("SET NAMES ' UTF8 '"), and at the front of the page with <?php header (' Content-type:text/html;charset=utf-8 ');? >[object object]<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

This encounter situation is phpmyadmin in the normal display, the page from the database extracted from the Chinese garbled for? , other display normal, first look at the database used in the character set and the database collation encoding format, and the page output when the character encoding set the same, there is no problem, still garbled, so I think, may be in the database to extract data from the encoding format is problematic, Then find the database connection file on the character encoding settings, found no setting, so use mysql_query ("Set names gb2312"); The data extracted from the database in gb2312 encoding format output, at this time also page set encoding format is the same, the page normal display.

PHP read MySQL data to page garbled

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.