JpGraph中文乱码解决方案

来源:互联网 发布:服务器域名 编辑:程序博客网 时间:2024/05/12 12:55




http://blog.sina.com.cn/s/blog_72e855900100t8uh.html
在使用JpGraph时,经常会出现乱码问题,这种问题的原因多半都是因为字符编码不合适引起的,下面是一般的解决办法。针对2.3版本。

首先确保将simsun.ttc文件拷贝到/usr/X11R6/lib/X11/fonts/truetype下。该文件可以直接从winodws的字体库文件中找到。

$graph->title->set($title)乱码解决

在此jpGraph默认支持gb2312编码,如果出现乱码肯定是$title的编码是utf-8。

修改方法:

$title = iconv("UTF-8", "gb2312", $title);
$graph->title->Set($title);

如果需要修改的地方比较多,而且你确信代码中基本都用的是utf-8编码,可以直接修改jpGraph源文件

方法:修改文件:src/jpgraph_ttf.inc.php

elseif( $aFF === FF_SIMSUN ) {
        
// Do Chinese conversion
        
if( $this->g2312 == null
 ) {
         include_once
 'jpgraph_gb2312.php'
 ;
        
$this->g2312 = new GB2312toUTF8
();
         }
         return
 $this->g2312->gb2utf8($aTxt
);
     }
     elseif(
 $aFF === FF_CHINESE
 ) {
         if( !
function_exists('iconv'
) ) {
        
JpGraphError::RaiseL(25006
);
//('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).');
        
}
         return
 iconv('BIG5','UTF-8',$aTxt
);

将这里直接改为

elseif( $aFF === FF_SIMSUN ) {

         return
 $aTxt
;
     }
     elseif(
 $aFF === FF_CHINESE
 ) {

       return
 $aTxt;


SetLegend函数乱码解决
3、打开jpgraph.php文件,找到
private $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12;

private $font_family=FF_SIMSUN,$font_style=FS_NORMAL,$font_size=8;

原创粉丝点击