Ask for advice, how to judge whether it is low byte

Source: Internet
Author: User
Ask, how to determine whether it is low-byte?
 
  Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=GBK");
$str = "J This is CES test dkfjdksj";

function SUBSTR_GBK ($str, $start, $end)
{
$temp = "";
for ($i = $start; $i <= $end; $i + +)
{
if (Ord ($str {$i}) >0xa0)
{
$temp. =substr ($str, $i, 2);
$i + +;
}else
{
$temp. =substr ($str, $i, 1);
}
}
return $temp;
}

Echo SUBSTR_GBK ($str, 1,10); Intercept normal from high byte
Echo SUBSTR_GBK ($str, 2,10); Garbled truncation from low byte
?>


The above code is truncated from high byte without problem, but if truncation from low byte is garbled
Do you know how to determine the high and low byte method?

Share to:


------Solution--------------------
This post was last edited by xuzuning on 2013-10-30 11:08:53

$str = "J This is CES test dkfjdksj";

function SUBSTR_GBK ($str, $start, $end)
{
$temp = "";
for ($i =0; $i < $start; $i + +) if (Ord ($str {$i}) >0xa0) $i + +; Plus this line.
for (; $i <= $end; $i + +)
{
if (Ord ($str {$i}) >0xa0)
{
$temp. =substr ($str, $i, 2);
$i + +;
}else
{
$temp. =substr ($str, $i, 1);
}
}
return $temp;
}

Echo SUBSTR_GBK ($str, 1,10); This is the CES test.
Echo SUBSTR_GBK ($str, 2,10); It's a CES test.
  • 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.