Ask, how to determine whether it is low-byte?

Source: Internet
Author: User
 
  0xa0) {$temp. =substr ($str, $i, 2); $i + +;} else{$temp. =substr ($str, $i, 1);}} return $temp;} Echo SUBSTR_GBK ($str, 1,10); Intercept normal echo SUBSTR_GBK ($str, 2,10) from high bytes; Truncation from low byte garbled?>


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?


Reply to discussion (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 + +; Add 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.

What are the criteria for determining 0xa0?

GB2312 byte inside code starting from 0xa1

What are the criteria for determining 0xa0?

It's also garbled from 0XA1.

 
  0xa0) {$temp []=substr ($str, $i, 2); $i + +;} else{$temp []=substr ($str, $i, 1);}} Return implode ("", Array_slice ($temp, $start, $end));} Print_r (SUBSTR_GBK ($str, 0, 3));? >


It's a good way to use this soil, too inefficient.
Do you have any good ideas?

GB2312 byte inside code starting from 0xa1


What are the criteria for determining 0xa0?
I was surprised, he uses GBK, encounter 81 beginning of Chinese character how to do?


GB2312 byte inside code starting from 0xa1


What are the criteria for determining 0xa0?
I was surprised, he uses GBK, encounter 81 beginning of Chinese character how to do?


Well, boss, let's not get tangled up in this, okay? You tell me how to judge if it's a low-byte intercept. Thank you.

I thought you were studying algorithms, using MB_SUBSTR.

I thought you were studying algorithms, using MB_SUBSTR.

This has been tried, no.
You try the

 
  

Mb_substr ($str, 1,5, ' GBK ')

  • 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.