php专区

 首页 > php专区 > PHP应用 > php函数大全 > 在GD中输出汉字的函数 - php函数

在GD中输出汉字的函数 - php函数

分享到:
【字体:
导读:
          感谢sadly为我们写出了在GD中输出汉字的函数,我在使用中发现此版本输出的字符串必须为纯中文,不能夹杂英文,随修改了此bug,与大家分享。...

在GD中输出汉字的函数

感谢sadly为我们写出了在GD中输出汉字的函数,我在使用中发现此版本输出的字符串必须为纯中文,不能夹杂英文,随修改了此bug,与大家分享。

  1. //Program writen by sadly www.phpfensi.com 
  2. //modified by agun 2013/6/20 
  3. function gb2utf8($gb
  4. if(!trim($gb)) 
  5. return $gb
  6. $filename="gb2312.txt"
  7. $tmp=file($filename); 
  8. $codetable=array(); 
  9. while(list($key,$value)=each($tmp)) 
  10. $codetable[hexdec(substr($value,0,6))]=substr($value,7,6); 
  11. $ret=""
  12. $utf8=""
  13. while($gb
  14. if (ord(substr($gb,0,1))>127) 
  15. $this=substr($gb,0,2); 
  16. $gb=substr($gb,2,strlen($gb)); 
  17. $utf8=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080])); 
  18. for($i=0;$i<strlen($utf8);$i+=3) 
  19. $ret.=chr(substr($utf8,$i,3)); 
  20. else 
  21. $ret.=substr($gb,0,1); 
  22. $gb=substr($gb,1,strlen($gb)); 
  23. return $ret
  24. function u2utf8($c
  25. for($i=0;$i<count($c);$i++) 
  26. $str=""
  27. if ($c < 0x80) { 
  28. $str.=$c
  29. else if ($c < 0x800) { 
  30. $str.=(0xC0 | $c>>6); 
  31. $str.=(0x80 | $c & 0x3F); 
  32. else if ($c < 0x10000) { 
  33. $str.=(0xE0 | $c>>12); 
  34. $str.=(0x80 | $c>>6 & 0x3F); 
  35. $str.=(0x80 | $c & 0x3F); 
  36. else if ($c < 0x200000) { 
  37. $str.=(0xF0 | $c>>18); 
  38. $str.=(0x80 | $c>>12 & 0x3F); 
  39. $str.=(0x80 | $c>>6 & 0x3F); 
  40. $str.=(0x80 | $c & 0x3F); 
  41. return $str
  42. Header("Content-type: image/gif"); 
  43. $im = imagecreate(300,150); 
  44. $bkg = ImageColorAllocate($im, 0,0,0); 
  45. $clr = ImageColorAllocate($im, 255,255,255); 
  46. $fnt = "c:windowsfontssimsun.ttf"
  47. //include("gb2utf8.php"); 
  48. $str = gb2utf8("中国agun阿棍"); 
  49. ImageTTFText($im, 30, 0, 50,50, $clr$fnt$str); 
  50. ImageGif($im); 
  51. ImageDestroy($im); 
  52. ?> 
分享到:
phpMailer 发送邮件 - php函数
phpMailer 发送邮件 昨天听一网友说用php 里面的mail发邮件发不出去,我想一般都是发不了的,现在大多数据邮件提供商都不准那样了,下面我们就用phpmailer进行了吧,先到tom.com注册一个邮箱吧. function smtp_mail ($accept_email,$accept_name,$accept_info) {   $mail    = ...
一个取得文件扩展名的函数 - php函数
一个取得文件扩展名的函数   
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……