Home >Backend Development >PHP Problem >What to do if php outputs garbled characters to the browser
Solution to garbled php output to the browser: 1. Open the corresponding php file; 2. Add "header('Content-Type: text/html; charset=utf- 8');" statement is enough.
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
How to output garbled characters to the browser manage?
The PHP file is garbled when opened with a browser
When writing web pages in PHP, I found that using PHP When the file is opened in the browser, it is all garbled, like this:
Looking for online information, I found that adding header('Content-Type: text/html;charset=utf-8'); Just fine,
The reason is that the encoding parsed by the browser is inconsistent with PHP.
This sentence tells the browser to use utf- 8 Encoding parsing PHP return data.
## Recommended study: "PHP Video Tutorial"
The above is the detailed content of What to do if php outputs garbled characters to the browser. For more information, please follow other related articles on the PHP Chinese website!