Home > Daily Programming > PHP Knowledge > How to solve the problem of garbled text and pictures in PHP? (Pictures + Videos)

How to solve the problem of garbled text and pictures in PHP? (Pictures + Videos)

藏色散人
Release: 2018-10-17 11:13:17
Original
5224 people have browsed it

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");         //设置编码
Copy after login

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

How to solve the problem of garbled text and pictures in PHP? (Pictures + Videos)

Then change to "UTF-8"

How to solve the problem of garbled text and pictures in PHP? (Pictures + Videos)

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");//图片编码设置
Copy after login

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!

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