时间:2021-07-01 10:21:17 帮助过:11人阅读
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); ?>
解决办法:
$text = mb_convert_encoding("呵呵呵","UTF-8","GBK");改成$text = mb_convert_encoding("呵呵呵","html-entities","UTF-8");即可。
推荐学习:《PHP视频教程》
以上就是php图片写入中文乱码怎么办的详细内容,更多请关注gxlcms其它相关文章!