经过我的研究发现,造成此问题有下面这两个原因:
- 星期几名称缩写的截取函数有问题。代码中使用英文单词取前3个字符的截取方式,例如:Monday-> Mon。可是当截取汉字的时候就生成了一个半汉字。
- 可能是个Bug,例如原文件“dotProject\modules\calendar\calendar.class.php”
中生成标题字符串的程序代码为:
$s .= "\n\t\t<th width=\"14%\">" . htmlentities(utf8_encode($day), ENT_COMPAT, $locale_char_set) . "</th>";
至于改进方式,我采用了比较偷懒的方式,直接设置了星期几名称的数组,然后去掉第2个问题中的utf8编码函数调用,问题解决。下面是我修改后的函数代码:
function _drawDays() {
global $locale_char_set;
$bow = Date_Calc::beginOfWeek( null,null,null,null,LOCALE_FIRST_DAY );
$y = substr( $bow, 0, 4 );
$m = substr( $bow, 4, 2 );
$d = substr( $bow, 6, 2 );
$wk = Date_Calc::getCalendarWeek( $d, $m, $y, "%a", LOCALE_FIRST_DAY );
if($locale_char_set=='GB2312')
{
$wk = array('日','一','二','三','四','五','六');
}
$s = $this->showWeek ? "\n\t\t<th> </th>" : "";
foreach( $wk as $day ) {
//$s .= "\n\t\t<th width=\"14%\">" . htmlentities(utf8_encode($day), ENT_COMPAT, $locale_char_set) . "</th>";
$s .= "\n\t\t<th align=\"center\" width=\"14%\">" . htmlentities($day, ENT_COMPAT, $locale_char_set) . "</th>";
}
return "\n<tr>$s\n</tr>";
}
global $locale_char_set;
$bow = Date_Calc::beginOfWeek( null,null,null,null,LOCALE_FIRST_DAY );
$y = substr( $bow, 0, 4 );
$m = substr( $bow, 4, 2 );
$d = substr( $bow, 6, 2 );
$wk = Date_Calc::getCalendarWeek( $d, $m, $y, "%a", LOCALE_FIRST_DAY );
if($locale_char_set=='GB2312')
{
$wk = array('日','一','二','三','四','五','六');
}
$s = $this->showWeek ? "\n\t\t<th> </th>" : "";
foreach( $wk as $day ) {
//$s .= "\n\t\t<th width=\"14%\">" . htmlentities(utf8_encode($day), ENT_COMPAT, $locale_char_set) . "</th>";
$s .= "\n\t\t<th align=\"center\" width=\"14%\">" . htmlentities($day, ENT_COMPAT, $locale_char_set) . "</th>";
}
return "\n<tr>$s\n</tr>";
}