A detailed explanation of garbled problems when making Web pages

Source: Internet
Author: User
Tags phpmyadmin server memory

A detailed explanation of garbled problems when making Web pages

Many friends in the production of Web pages will encounter a very headache problem, is garbled problem, sometimes change the code to solve, it is good luck, and sometimes can not solve, there is no way. I also encountered a lot of problems in the production of web pages, and finally really can not stand, had to spend three days to carefully study the garbled problem, small results, here and everyone to share.

Garbled in my opinion in three kinds of situations:

1.html garbled.

2.javascript garbled

3. Database garbled (I use MySQL, the other same, the operation of the database is directly using phpMyAdmin operation)

Web design basically in these three kinds of situations. The author of the unfortunate all met (is this a coincidence?) But fortunately, after reading a lot of relevant information and understanding the garbled principle in depth, it has been solved.

Note: No matter what kind of garbled problem, the author here suggested to make a Web page before the database, page encoding unified for UTF8 or gb231. This is a good habit, this habit will reduce the occurrence of unnecessary garbled problems.

Tools/Materials
    • You have a Dreamweaver word to solve HTML garbled will be very convenient. (not required)
    • You have a wamp words, inside with phpMyAdmin, will let you solve the database garbled very convenient. (also not required)
Method/Step
  1. 1

    HTML garbled solution

    1. You don't have Dreamweaver:

    <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8"/> < /strong>

    Copy this line of code between your all page encoding Unified , are set to UTF8, or both are set to gb2312.

    2. If you have Dreamweaver:

    You don't have to remember this line of code, because Dreamweaver can be set,

    Select Page properties (also found in the above modification), select title/Encoding, Change encoding to ensure uniform encoding (unified UTF8 or gb2312)

    Select Unified Encoding and click Apply, and Dreamweaver will automatically add a line of code to your page.

    But remember, you want to unify the encoding. This is set up when you make the first page , and the benefit is that every page you edit later with Dreamweaver will automatically be encoded uniformly .

  2. 2

    JS garbled solution

    Here JS garbled refers to the content of the popup made by JS for garbled situation, this situation is very headache, but generally will not appear, if appear, not good solution.

    1. If your JS pop-up window content garbled, first check the original page code in the output is garbled (due to the page settings, resulting in the original character into garbled)

    2. If you make sure that your original Web page code is not garbled, then the content of JS output and page encoding does not match, then we should force the output content conversion encoding and page encoding unity.

    There are many ways to cast the encoding, and I've done it here with PHP

    <?php

    $ss =iconv ("UTF8", "gb2312// IGNORE "," You want to enter the kanji ");

    echo $ss;

    echo "<script language=javascript>alert (' $ss ');</script>";

    ;

    The advantage of the

    is that whether the page encoding is UTF8 or gb2312, your JS pop-up window content will not be garbled. But the disadvantage is also obvious, your file suffix name from . html needs to be changed to . PHP (otherwise PHP is not compiled) , and PHP execution consumes server memory, But just convert the encoding and don't worry about consuming too much server memory.

  3. 3

    The solution of database garbled

    Here the database garbled refers to

    1. after inserting normal data, garbled characters are displayed in the database.

    2. Normal data read out on the page display garbled

    3. Database (table, field) coding problems when establishing a database

    Workaround:

    1. force the data into code before inserting the database, and unify with the database. (the author uses PHP to operate the database here.)

    <?php

    $ss =iconv ("UTF8", "Gb2312//ignore", "you want to insert the kanji data");

    mysql_query ("INSERT into table name (field name) VALUES (' $ss ')");

    ?>

    This will not garbled when viewing data within the database. But if you unify the page encoding with the database code, this problem does not occur at all.

    2. Normal data read out in the page garbled, first check the database content is garbled, if it is, refer to Method 1: "Insert normal data, the database display garbled" solution, then the data in the database is normal, but the page output is still garbled, Indicates that the HTML encoding is problematic or not uniform. Refer to "HTML garbled resolution ".

    3. You will adjust the page uniform encoding, database encoding is not uniform, you do not want to delete the database re-establishment. Too many places to insert data, what to do, we have to change the database code.

    Open phpMyAdmin. , select the operation of the database--organize, and then unify the encoding.

    Change the database and then check the data table "collation", confirm the code Unified!!

  4. 4

    Here is the establishment of a database unified code method, if you do so will not encounter garbled problem!! Next time remember. It is most convenient to unify when building a table.

    END
Precautions
    • No matter what kind of garbled question, the author here suggests to make a Web page before the database, page encoding unified to UTF8 or gb231. This is a good habit, this habit will reduce the occurrence of unnecessary garbled problems.

A detailed explanation of garbled problems when making Web pages

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.