php图片写入中文乱码的解决办法:首先打开相应的PHP代码文件;然后将mb_convert_encoding("...","UTF-8","GBK");改成“"html-entities","UTF-8"”即可。
本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
具体问题:
在php绘图时,往图片中写入中文是成功的,但是显示出来的中文是一些生僻字。
$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); ?>
解决办法:
立即学习“PHP免费学习笔记(深入)”;
$text = mb_convert_encoding("呵呵呵","UTF-8","GBK");改成$text = mb_convert_encoding("呵呵呵","html-entities","UTF-8");即可。
推荐学习:《PHP视频教程》
以上就是php图片写入中文乱码怎么办的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号