国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

圖象函數中的中文顯示

2024-05-04 23:01:03
字體:
來源:轉載
供稿:網友
  • 網站運營seo文章大全
  • 提供全面的站長運營經驗及seo技術!
  • 把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);

    ?>
    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 体育| 通州区| 荣昌县| 革吉县| 谢通门县| 桑植县| 淮安市| 罗平县| 卢龙县| 尼勒克县| 江阴市| 上饶市| 固始县| 涞水县| 巧家县| 太仓市| 濮阳市| 鄱阳县| 广州市| 巴里| 乌拉特后旗| 柳江县| 大洼县| 淮滨县| 洪洞县| 泾川县| 宽甸| 阿克| 鄂尔多斯市| 林周县| 泽库县| 昂仁县| 中江县| 兖州市| 永顺县| 江油市| 桂林市| 金门县| 蓝山县| 海城市| 新乡市|