Home >Backend Development >PHP Tutorial >Solving the problem of garbled Chinese verification code generated by PHP (1/2)_PHP tutorial
Solution to the problem of garbled Chinese verification code generated by PHP
//The Chinese characters to be processed are first converted from UTF8 Chinese characters into html entity form before use.
//Sample code:
//ini_set('JIS-mapped Japanese Font Support',false);
$pic=imagecreate(250,30);
$black=imagecolorallocate($pic,0,0,0);
$white=imagecolorallocate($pic,255,255,255);
$font="C://WINDOWS//Fonts//simhei.ttf";
$str = 'People's Republic of China';
$str = mb_convert_encoding($str, "html-entities","utf-8" );//Result:哪一队优先开& #29699;
imagettftext($pic,10,0,10,20,$white,$font,$str);
header("Content-type: image/jpeg");
$filename='./photo.jpg';
$im=imagecreatefromjpeg($filename);
imagecopymerge($im,$pic,0,0,0,0,250,30,50);
imagejpeg($im);
//pChart sample code:
/*
Example14: A smooth flat pie graph
*/
1 2