Home  >  Article  >  Backend Development  >  Summary of solutions to apache php garbled characters

Summary of solutions to apache php garbled characters

藏色散人
藏色散人Original
2020-07-13 10:00:292706browse

Solution to Apache PHP garbled code: 1. Modify the "httpd.conf" configuration; 2. Add UTF8 encoding to the head tag; 3. Save the file encoding as "UTF-8"; 4. Add the code "charset=utf-8" to the PHP page.

Summary of solutions to apache php garbled characters

Apache PHP solves the problem of Chinese garbled characters

1 Apache httpd.conf configuration.

AddDefaultCharset OFF

Second method to solve the problem of Chinese garbled characters in HTML

1. Add UTF8 encoding (international encoding) in the head tag: UTF-8 is an encoding without a country , that is, independent of any language and can be used in any language.

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

2. Save the file encoding as UTF-8. Editors such as Notepad or Editplus have the function of selecting encoding when saving.

Three HTML and PHP mixed page solutions

In addition to following the second method, you also need to add this sentence at the top of the file Code:

    <?php 
    header("Content-type:text/html;charset=utf-8");
    ?>

Chinese garbled problem of four pure PHP pages (data is static)

This only needs to add the following code at the beginning of the page, and then save the UTF -8 encoded files are sufficient.

    <?php
    header("Content-type:text/html;charset=utf-8");
    ?>

五PHP Mysql Chinese garbled problem

In addition to following the operations mentioned in point 4, this must also be done before querying/modifying/adding your data Add database encoding. Moreover, it is worth noting that the UTF8 here is different from the previous one, there is no horizontal line in the middle.

    <?php
    mysql_query(&#39;SET NAMES UTF8&#39;);
    //接下来的就是数据的增删查改
    ?>

Six, correctly display the Chinese name of the uploaded attachment

Find the file config.php in xampp/moodle,

In $CFG-> Add $CFG->unicodecleanfilename = true;

after uncodedb = true; to make the uploaded attachment display the Chinese name correctly.

7 When choosing to upload files in the IE browser, garbled characters may be displayed. You can add this sentence to the second line of

lib/editor/htmlarea/coursefiles.php

: // You can use: set nu displays the line number

@header("Content-Type: text/html; charset=utf-8");  //这个是默认选择utf-8编码

For more related knowledge, please visit PHP Chinese website!

The above is the detailed content of Summary of solutions to apache php 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