php graph 中文乱码,JpGraph中文乱码解决方案

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-23 12:43   11   0

在使用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 conversionif(

$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;

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP