Home  >  Article  >  Backend Development  >  What to do if php print r is garbled?

What to do if php print r is garbled?

藏色散人
藏色散人Original
2020-09-29 10:00:242490browse

php The solution to garbled print r: first set "header("content-type:text/html;charset=utf-8")"; then unify the encoding settings of files and databases.

What to do if php print r is garbled?

Recommended: "PHP Video Tutorial"

Specific questions:

php uses print_r to output garbled characters where to set the encoding

print_r($result);The result is shown as follows:

�����﷨����ȷ��

Where should the encoding be set? I want to temporarily set up the Chrome browser to view the content, but the encoding setting option is not found in version 60.

Solution:

1. Chrome no longer has this function.

If you are writing PHP, it is recommended to analyze $result first. The browser is a terminal, and you still have to check the source code in the end.

Set header("content-type:text/html;charset=utf-8") to ensure that it is not a problem with PHP output

2. First: When garbled characters appear, please encode the program: File encoding, database encoding, output encoding, etc. It is best to use uniform ones.

Secondly: The new version of chrome has removed the function of setting encoding because the frequency of use is too low. You can modify the encoding by installing an extension: Charset

The above is the detailed content of What to do if php print r is garbled?. 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