Home > Backend Development > PHP Problem > What to do if php pictures are written with Chinese garbled characters

What to do if php pictures are written with Chinese garbled characters

藏色散人
Release: 2023-03-09 18:56:01
Original
2013 people have browsed it

Solution to writing garbled Chinese characters into php images: First open the corresponding PHP code file; then change mb_convert_encoding("...","UTF-8","GBK"); to ""html -entities","UTF-8"" is enough.

What to do if php pictures are written with Chinese garbled characters

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

Specific questions:

When drawing in PHP, writing Chinese into the picture is successful, but the Chinese displayed are some rare characters.

$im = imagecreatetruecolor(400,40);    
$black = imagecolorallocate($im,0,0,0);    
$white = imagecolorallocate($im,255,255,255);    
$grey = imagecolorallocate($im,128,128,128);    
imagefilledrectangle($im,0,0,399,39,$white);    
$text = mb_convert_encoding("呵呵呵","UTF-8","GBK");    
$font = "simsun.ttc";    
imagettftext($im,20,0,12,21,$grey,$font,$text);//输出灰色字符串作为阴影    
imagettftext($im,20,0,10,20,$black,$font,$text);//输出黑色字符串作为文本    
header("Content-type:image/png");    
imagepng($im);    
imagedestroy($im);    
?>
Copy after login

Solution:

$text = mb_convert_encoding("Hehehe","UTF-8","GBK");Change to $text = mb_convert_encoding("Hehehe","html-entities","UTF-8"); That's it.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php pictures are written with Chinese garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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