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