php 截取字符串摘要

2018-03-01T18:00:00
function cSubStr( $str, $len, $flag = true)
{
    if(mb_strlen($str) < $len) return $str;
    $i = 0;
    $tlen = 0;
    $tstr = '';
    while ( $tlen < $len )
    {
        $tlen++;
        $chr = mb_substr( $str, $i, 1, 'utf8' );
        if ( $tlen > $len ) break;
        $tstr .= $chr;
        $i++;
    }
    if ( $tstr != $str && $flag )
    {
        $tstr .= '...';
    }
    return $tstr;
}
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »