PHP generated Chinese verification code garbled problem solving
The Chinese characters to be processed are first converted into HTML entities and reused by UTF8.
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"):& #21738;& #19968;& #38431;& #20248; & #20808;& #24320;& #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
*/
Standard inclusions
Header ("content-type:text/html; Charset=utf-8 ");
Include_once ("pchart/pdata.class.php tutorial");
Include_once ("pchart/pchart.class.php");
Dataset definition
$DataSet = new PData;
$DataSet->addpoint (Array (10,2,3,5,3), "Serie1");
$DataSet->addpoint (Array ("Iconv_arr", "February", "March", "APR", "may"), "Serie2");
$DataSet->addallseries ();
$DataSet->setabsciselabelserie ("Serie2");
Initialise the graph
$Test = new Pchart (300,200);
$Test->loadcolorpalette ("Sample/softtones.txt");
$Test->drawfilledroundedrectangle (7,7,293,193,5,240,240,240);
$Test->drawroundedrectangle (5,5,295,195,5,230,230,230);
Draw the pie chart
$Test->setfontproperties ("Fonts/simkai.ttf", 8);
$Test->drawbasicpiegraph ($DataSet->getdata (), $DataSet->getdatadescription (), 120,100,70,pie_percentage , 255,255,218);
$Test->drawpielegend (230,15, $DataSet->getdata (), $DataSet->getdatadescription (), 250,250,250);
$Test->render ("Example14.png");
/**
* Convert text from UTF8 encoding to digital form encoding (HTML entity)
* @param $arr This parameter can be an array or string
* @author Steven lxq70361@qq.com
*/
function Iconv_arr ($arr) {
if (Is_array ($arr)) {
foreach ($arr as $k => $v) {
$arr [$k] = Iconv_arr ($v);
}
}else{
$arr = mb_convert_encoding ($arr, "html-entities", "utf-8");
}
return $arr;
}