字符串截取函数

690阅读 0评论2010-09-17 dongyue91
分类:

字符串截取:

function cutstr($str, $length, $dot='…',$charset='utf-8')
{
    if(strtolower($charset) == 'utf-8')
    {
        $str = mb_convert_encoding($str, 'gb2312', 'utf-8');
    }
    if($length >= strlen($str))
    {
        return mb_convert_encoding($str, 'utf-8', 'gb2312');;
    }
    for($i=0;$i<$length-2;$i++)
    {
        $str_new .= $str[$i];
    }
    if(strtolower($charset) == 'utf-8')
    {
        $str_new = mb_convert_encoding($str_new, 'utf-8', 'gb2312');
    }
    //ord()
    return $str_new.$dot;
}


上一篇:统计报表图实现 open flash chart OFC
下一篇:mysql explain结果介绍