V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
andreu
V2EX  ›  问与答

FFFD是很闹心的~

  •  
  •   andreu · Feb 15, 2011 · 4835 views
    This topic created in 5556 days ago, the information mentioned may be changed or developed.
    一个小问题想要请教,在首页截一段文字显示时,末梢文字碎片FFFD。

    <?php echo substr(get_the_excerpt(), 0, 120); ?>
    <?php if(strlen(get_the_excerpt()) > 120) : ?>...<?php endif; ?>
    这是模板中截取文字那段,我的文章是中、英、韩文混搭,所以经常出现末梢FFFD,我谷歌了如下代码:

    function gylsubstr($title,$length){
    if($length!=0){
    if (strlen($title)>$length) {
    $temp = 0;
    for($i=0; $i<$length; $i++)
    if (ord($title[$i]) > 128)
    $temp++;
    if ($temp%2 == 0)
    $title = substr($title,0,$length);
    else
    $title = substr($title,0,$length+1);
    }
    return $title;
    }else{return $title;}
    }
    据说这样可以解决,奈何我小白一个不知如何套用,麻烦各位高手指点,谢谢~
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   864 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:49 · PVG 02:49 · LAX 11:49 · JFK 14:49
    ♥ Do have faith in what you're doing.