升级Hdwiki4.0遇到的俩问题
第一个问题:从”Form”获取的字符非得经历从gbk转到utf-8或者从utf-8转到gbk一次吗?
hdwiki4.0版本(8.21发布)的 string.class.php中的字符编码转换函数
function hiconv($str,$to=”,$from=”) {
global $encoding;
if(empty($to))$to=$encoding;
if(empty($from)){
if( strtolower($encoding)==’gbk’ ){$from=’utf-8′;}else{$from=’gbk’;}
}
$to=strtolower($to);
$from=strtolower($from);
$isutf8=preg_match( ‘/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/’, $str );
if( $isutf8 && $to==’utf-8′ ) return $str;
if( !$isutf8 && $to==’gbk’ ) return $str;
require_once(‘Chinese.class.php’);
$ch = new chinese($from,$to);
$str= $ch->convert($str);
return $str;
}
为啥 if( strtolower($encoding)==’gbk’ ){$from=’utf-8′;}else{$from=’gbk’;}
这样呢,非得经历从gbk转到utf-8或者从utf-8转到gbk一次吗?为什么呢?
相关帖子:
http://kaiyuan.hoodong.com/bbs/viewthread.php?tid=2870&extra=page%3D6
第二个问题:hdwiki的ie下查看页面源码出现“中文乱码”现象!
另外hdwiki的ie下查看页面源码出现“中文乱码”现象,问题原来越清晰啦,就是获取到多余的字符,最初发现是在页脚处的“友情链接说明”内容过多(两个未知字节),造成页脚错位,而后发现词条页面过多的“摘要”内容(同样是两个未知字节)导致词条页面,使用ie查看页面源码出现“中文乱码”现象(再重新编辑摘要,刷新页面后验证正常),目前首页剩下最后一处可能造成“错误”原因就是还有一处乱码没有清理(移到友情链接中间的一个友情链接的(多两个字节)说明内容)。
就目前来看问题应该是出在没有处理好读取到的多余的两个字节上。
PS:另外可能出问题的关键字可能还有:站名,文章标题,标签,分类说明
PS:从原来有数据并且编写的都不怎么规范升级到4.0就可能出现这个情况
PS:$summary默认的数据库长度是250字节(从upgrade13.php中得知)。。。
在doc.php中
$doc['summary']=trim(string::convercharacter(string::substring(strip_tags($doc['summary']),0,100)));
是不是说明$summary只正常接收100个字节呢,
顺便提一下,这个$summary在入库前没有经过检查,并且这个是管理员不可以控制的部分(只要是有编辑权限的都可以去写摘要吧),同时他会导致页面代码错乱(字符编码问题?还是字节超出问题?),那么有没有可能构造异常的摘要,而在其后放入不正常的代码呢?(因为数据库中的$summary部分还可以存入150字节呢),如果想办法让substring处理异常会有这个可能吧!!
doc.php中docreate函数
行108到124
if(@!(bool)$this->post['summary']){
$doc['summary']=trim(strip_tags($_ENV['doc']->replace_danger_word($this->post['summary'])));
}
$doc['letter']=string::getfirstletter($this->post['title']);
$doc['category']=$this->post['category'];
$doc['title']=string::substring(string::stripspecialcharacter(trim($this->post['title'])),0,80);
$doc['tags']=$_ENV['doc']->jointags($this->post['tags']);
$doc['content']=string::stripscript($_ENV['doc']->replace_danger_word($this->post['thcTextarea']));
$doc['summary']=trim(strip_tags($_ENV['doc']->replace_danger_word($this->post['summary'])));
$doc['summary']=(bool)$doc['summary']?$doc['summary']:$doc['content'];
$doc['summary']=trim(string::convercharacter(string::substring(strip_tags($doc['summary']),0,100)));
$doc['images']=util::getimagesnum($doc['content']);
$doc['time']=$this->time;
$doc['words']=string::hstrlen($doc['content']);
$doc['visible']=$this->setting['verify_doc']?’0′:’1′;
$result=$_ENV['doc']->add_doc($doc);
doc.class.php中add_doc函数
行107到123
function add_doc($doc) {
$this->db->query(“insert into “.DB_TABLEPRE.”doc
(cid,letter,title,tag ,summary ,content,author,authorid,time,lastedit,lasteditor,visible)
values (‘”.$doc['category'].”‘,’”.$doc['letter'].”‘,’”.$doc['title'].”‘,’”.$doc['tags'].”‘,’”.$doc['summary'].”‘,’”.$doc['content'].”‘,
‘”.$this->base->user['username'].”‘,’”.$this->base->user['uid'].”‘,
“.$doc['time'].”,”.$doc['time'].”,’”.$this->base->user['username'].”‘,’”.$doc['visible'].”‘)”);
$did=$this->db->insert_id();
$this->db->query(“insert into “.DB_TABLEPRE.”edition
(cid,did,author,authorid,time,ip,title,tag,summary,content,words,images )
values (‘”.$doc['category'].”‘,$did,’”.$this->base->user['username'].”‘,’”.$this->base->user['uid'].”‘,
‘”.$doc['time'].”‘,’”.$this->base->ip.”‘,’”.$doc['title'].”‘,’”.$doc['tags'].”‘,’”.$doc['summary'].”‘,’”.$doc['content'].”‘,’”.$doc['words'].”‘,’”.$doc['images'].”‘)”);
return $did;
}
苦于对php不了解,上边的俩问题如果遇到大虾就别笑我呢!!
wiki地址:http://wiki.clin003.com/wiki/Hdwiki4
转载原创文章请注明,转载自:Lin's Space|Only[http://clin003.com]
本文链接: http://clin003.com/wiki/between-utf-8-and-gbk-1451/
Google比较注重原创性和时效性,若没有找到需要的内容可尝试以下搜素。
新鲜评论