1、尽量使用UTF-8,这就要求
(1)所有的源文件都要存储成utf-8格式。
(2)所有的页都要指明encoding,注意下面带utf-8的地方
html页面:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
PHP文件:
header('Content-type: text/html; charset=utf-8');
Dojo.bind:
dojo.io.bind({
url: 'test_sybaseSearch.php',
handler: searchCallback,
encoding: "utf-8",
content: {name: dojo.byId('name').value } });
2、对于一些非utf-8编码的数据要进行转换,注意下面带utf-8的地方
(1)MySQL数据库
$db->query("set names 'utf8'");
这句用在从数据库里面取数据之前,制定输出的编码集为utf-8(注意没有了'-'),当然也可以把utf8换成gb2312。
(2)Sybase数据库
iconv("gb2312", "utf-8", $row[1])
这句是把数据库输出的数据从gb2312转换成utf-8,当然输入到数据库则需反其道而行之。
对于Sybase而言要多说几句,它的编码集在Server端和Client端是各设各的,可以一样也可以不一样。而且Server和Client端所在的平台的编码集也不近相同,所以在处理的时候头脑要清醒。手册地址:
是E文的。大意就是:如何安装字符集以及如何设置转换表。我遇到的情况是这样的:
Server端的编码是cp850,Client端的平台是Linux,编码集是zh_CN.UTF-8。结果运行isql是出错,提示信息是
Using locale name "zh_CN.UTF-8" defined in environment variable LANG
Locale name "zh_CN.UTF-8" doesn't exist in your
/usr/local/sybase/locales/locales.dat file
编辑$SYBASE/locales/locales.dat,添加下面的命令
locale = zh_CN.UTF-8, chinese, utf8
意思是把utf8编码专程本地的utf-8。结果isql连接到服务器,但却给出信息如下
Msg 2401, Level 11, State 2:
Server 'house':
Character set conversion is not available between client character set
'utf8'
and server character set 'cp850'.
No conversions will be done.
Msg 4017, Level 16, State 1:
Server 'house':
Neither language name in login record 'chinese' nor language name in
syslogins
'<NULL>' is an official language name on this SQL Server. Using
server-wide
default 'us_english' instead.
还是不行呀。想了一会,干脆把本地的环境变量LANG改成en_US,结果一切正常,在数据库输出数据时,把终端(pietty)的字符编码集改成gb2312,一切ok!