PHP string Interception Chinese interception 2, single byte interception mode _php technique

Source: Internet
Author: User
Tags strlen
Chinese interception 2, single byte interception mode
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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.