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)

Oct 17, 2018 am 11:13 AM

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)