用iconv
$str = iconv("GB2312","UTF-8","图片显示中文");
$str = iconv("GB2312","UTF-8","图片显示中文");
解决方案 »
- (散分)这段代码把我整疯了——闲着无聊就来看看这问题吧
- php关于动态表单的验证
- input type为复选框的时候,name和value有什么不同?怎么用?
- 关于sendmail和Jmail的问题
- [深圳/東莞 | 求職] PHP或ASP程序員
- 截取简体中文函数,遇到繁体,特殊符号时出错!100分.
- 请教高手这个SQL语句怎么写?我有一个表,里面有三个字段,一个字段是时间[posttime],另一个字段是用户ID[UID],还有一个字段是帖子ID[ID],我
- 新版php在比对未声明变量出错误提示?
- 可以用PHP程序实现postgre数据库备份与恢复吗?
- thinkphp分页和跳页
- 谁做过在线html编辑器和数据库结合的,给个例子看看拉!谢谢啦!有的话给我一分,thx!
- 那位大虾给我介绍一下 PHP 呀?新手,谢谢!
<?//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;
}
?>还需要一个对照文本。去下一个。
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);
?>
大家帮我看看是怎么回事啊?<?
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);?>
==========================================================
不成才怪!想用iconv();
php.ini中:
extension=php_iconv.dll;去掉注释.
文件dlls/iconv.dll是否复制到系统目录下?
并需保证php版本在4.3.0以上,否则加载了也不支持gb2312使用对照表转换需下载gb2312.txt文件,230k。不过这张表也可以自行构造