Summary of solutions to apache php garbled characters

藏色散人
Release: 2023-03-02 13:08:01
Original
2722 people have browsed it

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
Copy after login

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"/>
Copy after login

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");
    ?>
Copy after login

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");
    ?>
Copy after login

五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;);
    //接下来的就是数据的增删查改
    ?>
Copy after login

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
Copy after login

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

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

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!

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