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 ')