一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

PHP 生成中文验证码乱码问题解决

时间:2022-06-25 00:00:49 编辑:袖梨 来源:一聚教程网

//将要处理的汉字,先由UTF8的汉字转成html实体形式再使用.

//示例代码:

 代码如下 复制代码
//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 = '中华人民共和国';
$str = mb_convert_encoding($str, "html-entities","utf-8" );//结果:哪一队优先开球

 代码如下 复制代码

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 示例代码:

/*
     Example14: A smooth flat pie graph
*/

 

 

 代码如下 复制代码

// Standard inclusions  
header("content-type:text/html; charset=utf-8");
include_once("pChart/pData.class.php教程");
include_once("pChart/pChart.class.php");
// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(10,2,3,5,3),"Serie1");
$DataSet->AddPoint(iconv_arr(array("Jan","二月","三月","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");

/**
* 将文本由UTF8编码转化为数字形式编码(HTML实体)
* @param $arr 该参数可以为数组或者string
* @author Steven [email protected]
*/
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;
}

热门栏目