关 键 词:
显示 中文 函数 图象 gb chr str. substr 0x80 im if
代码如下:
<?
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开发资源论坛讨论。
相关文章
图文推荐
论 坛 资 源
·Zope的优点及和Apache+PHP+MySQL的比较
·PHP面向对象、类经典教程[2]
·PHP面向对象、类经典教程[1]
·用 Xdebug 修正 PHP 应用程序中的错误(5)
·用 Xdebug 修正 PHP 应用程序中的错误(4)
·用 Xdebug 修正 PHP 应用程序中的错误(3)
·用 Xdebug 修正 PHP 应用程序中的错误(2)
·用 Xdebug 修正 PHP 应用程序中的错误(1)
·黑防黑:黑客口述—关于Php后门的隐藏技巧
·PRADO框架TDataGrid使用教程(1)
·PHP面向对象、类经典教程[2]
·PHP面向对象、类经典教程[1]
·用 Xdebug 修正 PHP 应用程序中的错误(5)
·用 Xdebug 修正 PHP 应用程序中的错误(4)
·用 Xdebug 修正 PHP 应用程序中的错误(3)
·用 Xdebug 修正 PHP 应用程序中的错误(2)
·用 Xdebug 修正 PHP 应用程序中的错误(1)
·黑防黑:黑客口述—关于Php后门的隐藏技巧
·PRADO框架TDataGrid使用教程(1)
热门技术文档
·Zope的优点及和Apache+PHP+MySQL的比较
·Windows 下的 PHP 扩展编程
·PHP面向对象、类经典教程[2]
·PHP面向对象、类经典教程[1]
·用 Xdebug 修正 PHP 应用程序中的错误(5)
·用 Xdebug 修正 PHP 应用程序中的错误(4)
·用 Xdebug 修正 PHP 应用程序中的错误(3)
·用 Xdebug 修正 PHP 应用程序中的错误(2)
·用 Xdebug 修正 PHP 应用程序中的错误(1)
·php时间求法(二)
·Windows 下的 PHP 扩展编程
·PHP面向对象、类经典教程[2]
·PHP面向对象、类经典教程[1]
·用 Xdebug 修正 PHP 应用程序中的错误(5)
·用 Xdebug 修正 PHP 应用程序中的错误(4)
·用 Xdebug 修正 PHP 应用程序中的错误(3)
·用 Xdebug 修正 PHP 应用程序中的错误(2)
·用 Xdebug 修正 PHP 应用程序中的错误(1)
·php时间求法(二)
最新图文档
本站编辑推荐:(本站开通Delphi4PHP专区,欢迎进入论坛交流!)
- · 3分钟快速了解 Delphi for PHP 特色 (中文), PDF档
- · 购买Delphi for PHP的五大理由, PDF档
- · Delphi for PHP 使用规格介绍, PDF档
- · Delphi for PHP 問答集 (From CodeGear)
- · Delphi for PHP 产品价格表
编缉最近更新文章
网站赞助商
搜索您感兴趣的内容




