用iconv
$str = iconv("GB2312","UTF-8","图片显示中文");

解决方案 »

  1.   

    系统提示:Call to undefined function:  iconv()
      

  2.   

    要一个函数。
    <?//Program writen by sadly www.phpx.comfunction 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));
    $utf8.=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080]));
    }
    else
    {
    $gb=substr($gb,1,strlen($gb));
    $utf8.=u2utf8(substr($gb,0,1));
    }
    }$ret="";
    for($i=0;$i<strlen($utf8);$i+=3)
    $ret.=chr(substr($utf8,$i,3));return $ret;
    }function u2utf8($c)
    {
    for($i=0;$i<count($c);$i++)
    $str="";
    if ($c < 0x80) {
    $str.=$c;
    }
    else if ($c < 0x800) {
    $str.=(0xC0 | $c>>6);
    $str.=(0x80 | $c & 0x3F);
    }
    else if ($c < 0x10000) {
    $str.=(0xE0 | $c>>12);
    $str.=(0x80 | $c>>6 & 0x3F);
    $str.=(0x80 | $c & 0x3F);
    }
    else if ($c < 0x200000) {
    $str.=(0xF0 | $c>>18);
    $str.=(0x80 | $c>>12 & 0x3F);
    $str.=(0x80 | $c>>6 & 0x3F);
    $str.=(0x80 | $c & 0x3F);
    }
    return $str;
    }
    ?>还需要一个对照文本。去下一个。
      

  3.   

    <?php
    Header("Content-type: image/png"); $im = imagecreate(400,50);
    $bkg = ImageColorAllocate($im, 128,64,225); 
    $clr = ImageColorAllocate($im, 255,255,255); $fnt = "c:\winnt\fonts\simsun.ttc";//定义字体文件
    $str = iconv("GB2312","UTF-8","大家好啊"); 
    ImageTTFText($im, 20, 0, 230,40, $clr, $fnt, $str); $black = ImageColorAllocate($im, 0,0,0);
    $white = ImageColorAllocate($im, 255,255,255);
    imageline($im, 1, 1, 350, 25, $black);
    imagearc($im, 200, 15, 20, 20, 35, 190, $white);
    imagestring($im, 5, 4, 10, "Graph TEST!!", $white);ImagePNG($im); 
    ImageDestroy($im); 
    ?>
      

  4.   

    下面是我的代码,用了上面两位的两种方法,可是不成的。
    大家帮我看看是怎么回事啊?<?
    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));
    $utf8.=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080]));
    }
    else
    {
    $gb=substr($gb,1,strlen($gb));
    $utf8.=u2utf8(substr($gb,0,1));
    }
    }$ret="";
    for($i=0;$i<strlen($utf8);$i+=3)
    $ret.=chr(substr($utf8,$i,3));return $ret;
    }function u2utf8($c)
    {
    for($i=0;$i<count($c);$i++)
    $str="";
    if ($c < 0x80) {
    $str.=$c;
    }
    else if ($c < 0x800) {
    $str.=(0xC0 | $c>>6);
    $str.=(0x80 | $c & 0x3F);
    }
    else if ($c < 0x10000) {
    $str.=(0xE0 | $c>>12);
    $str.=(0x80 | $c>>6 & 0x3F);
    $str.=(0x80 | $c & 0x3F);
    }
    else if ($c < 0x200000) {
    $str.=(0xF0 | $c>>18);
    $str.=(0x80 | $c>>12 & 0x3F);
    $str.=(0x80 | $c>>6 & 0x3F);
    $str.=(0x80 | $c & 0x3F);
    }
    return $str;
    }Header("Content-type: image/png");
    $im = imagecreate(400,300);
    $bkg = ImageColorAllocate($im, 0,0,0);
    $clr = ImageColorAllocate($im, 255,255,255);
    $fnt = "c:/winnt/fonts/simhei.ttf";$str="";
    //$str = iconv("GB2312","UTF-8","安全指数");     //---系统提示无此函数
    $str1=gb2utf8("深圳市");$str.=$str1;imagestring($im, 5, 4, 10, $str, $clr);
    ImageTTFText($im, 20, 0, 10, 20, $clr, $fnt, $str);
    ImagePNG($im);
    ImageDestroy($im);?>
      

  5.   

    "下面是我的代码,用了上面两位的两种方法,可是不成的。"
    ==========================================================
    不成才怪!想用iconv();
    php.ini中:
    extension=php_iconv.dll;去掉注释.
      

  6.   

    我无法加载php_iconv.dll,同样的路径下,gd库,mssql库等其他都可以,为何?
      

  7.   

    PHP版本?
    文件dlls/iconv.dll是否复制到系统目录下?
      

  8.   

    加载php_iconv.dll需要将php/dlls下的文件拷贝到系统目录下
    并需保证php版本在4.3.0以上,否则加载了也不支持gb2312使用对照表转换需下载gb2312.txt文件,230k。不过这张表也可以自行构造