Home > Backend Development > PHP Tutorial > PHP string interception Chinese interception 2, single byte interception mode_PHP tutorial

PHP string interception Chinese interception 2, single byte interception mode_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:54:06
Original
782 people have browsed it

//中文截取2,单字节截取模式
function cn_substr($str,$slen,$startdd=0){
    $restr = "";
    $c = "";
    $str_len = strlen($str);
    if($str_len < $startdd+1) return "";
    if($str_len < $startdd + $slen || $slen==0) $slen = $str_len - $startdd;
    $enddd = $startdd + $slen - 1;
    for($i=0;$i<$str_len;$i++)
    {
        if($startdd==0) $restr .= $c;
        else if($i > $startdd) $restr .= $c;

        if(ord($str[$i])>0x80){
            if($str_len>$i+1) $c = $str[$i].$str[$i+1];
            $i++;
        }
        else{    $c = $str[$i]; }

        if($i >= $enddd){
            if(strlen($restr)+strlen($c)>$slen) break;
            else{ $restr .= $c; break; }
        }
    }
    return $restr;
}
function cn_midstr($str,$start,$len){
    return cn_substr($str,$slen,$startdd);
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/318564.htmlTechArticle//中文截取2,单字节截取模式 functioncn_substr($str,$slen,$startdd=0){ $restr=""; $c=""; $str_len=strlen($str); if($str_len$startdd+1)return""; if($str_len$startdd+$slen|...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template