让wordpress 的 on this day插件支持中文截断

By SuperTaoer | 二月 13, 2009
Under: WordPress的
Views:

wp的on this day插件有点儿意思,比如今天是2009年2月13日,会显示出你在前几年的2月13日发表过的文章,偶尔回味一下,还真他妈回味无穷啊。。。

但是使用中发现了个问题,就是说在后台设置20个字的长度没有起作用,猜想到了可能不支持中文,于是乎查看插件的源代码,有如下的一段:

  1. $words = explode( , $text, $options['excerptLength'] + 1);
  2.     if (count($words)>$options['excerptLength']) {
  3.      array_pop($words);
  4.      array_push($words, [...]);
  5.      $text = implode( , $words);
  6.      }

 这段代码的意思也就是说按照空格来分割单词(老外的鸟儿语全JB这操行),然后取出前xxx个单词,但是咱爷们儿用的是中文,这不好使啊,就他妈改呗,将上边儿的那串儿注释掉,加入下面一行, 

  1. $text = mb_substr($text, 0, $options['excerptLength'] + 1, UTF-8) . [...];

 这就ok了,前提条件是你的php得支持mb_string的扩展。

差..好文!! (还没评价)
Loading ... Loading ...

Leave a Message

1 Message

Doesn’t this web page has English support?

 

RSS feed for comments on this post. TrackBack URI

Leave a Message