截取用户名中的部分字符

浏览:497 发布日期:2015/03/25 分类:技术分享
function mb_cutstr($string, $encode='UTF-8', $repeat='*', $count=3){
    $length = mb_strlen($string, $encode);
        
    if($length < 4){
        $head = mb_substr($string, 0, 1, $encode);
        $foot = ($length > 2)? mb_substr($string, -1, 1, $encode) : '';
    }else{
        $head = mb_substr($string, 0, 2, $encode);
        $foot = mb_substr($string, -1, 1, $encode);
    }
    return $head . str_repeat($repeat, $count). $foot;
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>