PHP中GD显示汉字--发个贴,顺便送点分。
function big52uni($text){
global $kindname;
$rtext="";
$max=strlen($text);
if($kindname=='tw'){
for($i=0;$i<$max;$i++){
$h=ord($text[$i]);
if($h>=160 && $i<$max-1){
$rtext.="&#".base_convert(bin2hex(iconv("big5","ucs-2",substr($text,$i,2))),16,10).";";
$i++;
}else{
$rtext.=$text[$i];
}
}
}else{
for($i=0;$i<$max;$i++){
$h=ord($text[$i]);
if($h>=160 && $i<$max-1){
$rtext.="&#".base_convert(bin2hex(iconv("gb2312","ucs-2",substr($text,$i,2))),16,10).";";
$i++;
}else{
$rtext.=$text[$i];
}
}
}
return $rtext;
}
$m_textfont = "../tool/simhei.ttf";
$kindname为编码类型,$text为要显示的汉字
simhei.ttf可以自己设定目录。
在LINUX下配置要支持freetype.