{$smarty.now|date_format:"%Y年%m月%d日"} 这样写就成了"2010年%m月%d日"+一些乱码如果给汉字后加上空格就正常了,但是输出也有了空格。

为了解决这个问题,我去读了smarty的插件代码modifier.date_format.php:
发现里面strftime这个PHP函数对于中文支持不好。
所以我修改了modifier.date_format.php函数,一劳永逸啊。大家可以直接复制替换原有内容即可。
而且我这个函数还是支持繁简中文的哦。呵呵
function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '')
{
   if (substr(PHP_OS,0,3) == 'WIN') {
           $_win_from = array ('%e',   '%T',        '%D');
           $_win_to    = array ('%#d', '%H:%M:%S', '%m/%d/%y');
           $format = str_replace($_win_from, $_win_to, $format);
    }
   $arrTemp = array('年','月','日','时','分','秒','時');
   foreach($arrTemp as $v){
     if(strpos($format,$v)){
       $strFormat = str_replace('%','',$format);
     }
   }
    if($string != '') {
    if(!empty($strFormat)) return date($strFormat, smarty_make_timestamp($string));
    else return strftime($format, smarty_make_timestamp($string));
    } elseif (isset($default_date) && $default_date != '') {
     if(!empty($strFormat)) return date($strFormat, smarty_make_timestamp($default_date));
        else return strftime($format, smarty_make_timestamp($default_date));
    } else {
        return;
    }

}
PHP | 评论(0) | 引用(0) | 阅读(7631)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]