Home > Article > Backend Development > What to do if php pictures are written with Chinese garbled characters
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.
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); ?>
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!