Home > Article > Daily Programming > How to solve the problem of garbled text and pictures in PHP? (Pictures + Videos)
This article mainly introduces to you the solutions to PHP Chinese garbled characters and image display garbled characters.
In the process of learning PHP, many novice friends must have encountered the problem of garbled characters. Solving the problem of garbled characters is not only a basic knowledge point that novices must master, but also the most common PHP interview. One of the questions.
Below we will summarize and introduce to you the solution when PHP encounters garbled characters based on simple code examples.
1. Chinese garbled characters on the PHP page
1. Header statement
<?php
header("content-type:text/html;charset=utf-8"); //设置编码When Chinese garbled characters appear on a PHP page , you can directly place this code in the head of the PHP page.
2. Change the php configuration file
First we open the php.ini configuration file
Find the corresponding location by searching for charset

Then change to "UTF-8"

Finally, reopen the PHP environment.
It should be noted here that when we use the first method, solving the garbled problem only takes effect on the current PHP page, while changing the configuration takes effect on all PHP pages.
2. The image displays garbled characters
To solve the problem of image displaying garbled characters, just add the following code to the header of the page, which is used to declare the image type.
<?php
header("Content-Type:image/jpg");//图片编码设置This article is an introduction to the solution to php garbled code and the solution to picture display garbled code. It is very simple. I hope it will be helpful to friends who need it. Helped!
If you want to know more about PHP, you can follow the PHP Chinese website PHP Video Tutorial, everyone is welcome to refer to and learn!
The above is the detailed content of How to solve the problem of garbled text and pictures in PHP? (Pictures + Videos). For more information, please follow other related articles on the PHP Chinese website!