代碼如下:
<?

function gb2utf8($gb)
{
if(!trim($g " /> 一区二区三区四区日本视频,国产精品www,国产精品网曝门

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

圖象函數中的中文顯示

把GB碼轉換到UTF8,php中TTF支持UTF8編碼的非ASCII字符輸出.在分析這段代碼之后,發現可以實現中文與ASCII混合輸出圖象,這樣在我們操作圖象函數時可以更方便.
代碼如下:
<?

function gb2utf8($gb)
{
if(!trim($gb))
return $gb;
$filename="gb2312.txt";
$tmp=file($filename);
$codetable=array();
while(list($key,$value)=each($tmp))
$codetable[hexdec(substr($value,0,6))]=substr($value,7,6);

$utf8="";
while($gb)
{
if (ord(substr($gb,0,1))>127)
{
$this=substr($gb,0,2);
$gb=substr($gb,2,strlen($gb)-2);
$utf8.=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080]));
}
else
{
$this=substr($gb,0,1);
$gb=substr($gb,1,strlen($gb)-1);
$utf8.=u2utf8($this);
}
}

/*$ret="";
for($i=0;$i<strlen($utf8);$i+=3)
$ret.=chr(substr($utf8,$i,3));

return $ret;*/

return $utf8;
}
function u2utf8($c)
{
/*for($i=0;$i<count($c);$i++)*/
$str="";
if ($c < 0x80) {
$str.=$c;
}
else if ($c < 0x800) {
$str.=chr(0xC0 | $c>>6);
$str.=chr(0x80 | $c & 0x3F);
}
else if ($c < 0x10000) {
$str.=chr(0xE0 | $c>>12);
$str.=chr(0x80 | $c>>6 & 0x3F);
$str.=chr(0x80 | $c & 0x3F);
}
else if ($c < 0x200000) {
$str.=chr(0xF0 | $c>>18);
$str.=chr(0x80 | $c>>12 & 0x3F);
$str.=chr(0x80 | $c>>6 & 0x3F);
$str.=chr(0x80 | $c & 0x3F);
}
return $str;
}
?>


--------------------------------------------
<?
Header ("Content-type: image/jpeg");
$im = imagecreate (800, 400);
$black = ImageColorAllocate ($im, 0, 0, 0);
$white = ImageColorAllocate ($im, 255, 255, 255);
include("gb2utf8.php");
$str=gb2utf8("aaa中過32434");
ImageTTFText ($im, 90, 10, 110, 300, $white, "/usr/share/fonts/default/TrueType/simsun.ttc",
$str);

ImageJPEG ($im);
ImageDestroy ($im);

?>

php技術圖象函數中的中文顯示,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 崇文区| 东光县| 特克斯县| 休宁县| 咸宁市| 台东市| 拉孜县| 叶城县| 阳东县| 扎兰屯市| 辽阳县| 中西区| 新建县| 娄底市| 陇川县| 芜湖县| 安阳县| 德钦县| 崇州市| 友谊县| 抚顺市| 五大连池市| 临夏市| 微博| 扶风县| 崇左市| 莲花县| 阆中市| 邵阳县| 长泰县| 施秉县| 驻马店市| 景谷| 江华| 鹤壁市| 鄄城县| 靖州| 剑阁县| 甘谷县| 墨玉县| 观塘区|