动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 图象函数中的中文显示

作者来源: 
阅读 1347 人次 , 2006-3-29 4:19:00 


把它email给我 我来谈谈我的看法 上一篇 下一篇

 

在www.phpx.com上读到一段代码,是把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);

?>

gb2312.txt文件请到www.phpx.com上找.

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:用PHP产生动态的影像图
· 下一篇:PHP与MySQL交互使用详解
· 用EMAIL附件传送一个文件(用mail)
· MySQL数据导入与导出
· 使用PHP实现繁体与简体互转
· 利用文件属性结合Session实现在线人数统计
· Multiple Selection


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077