|
This is obviously used to process the interception of a piece of Chinese characters, in ASCII, 0xa0 represents the beginning of the Chinese character
In PHP, a function ord () function
This function returns the Askii code value of a character;
such as Ord (' A ') = 65;
Take a look at this function
The implementation of the text string interception without garbled method.
For:
function Gbsubstr ($string, $start, $length) {
if (strlen ($string) > $length) {
$str =null;
$len = $start + $length;
for ($i = $start; $i <</span> $len; $i + +) {
if (Ord (substr ($string, $i, 1)) >0xa0) {
The Ord () function returns the ASCII (US National Code) ordinal value of the character. This function is the opposite of the Chr () function.
$str. =substr ($string, $i, 2);
$i + +;
}else{
$str. =substr ($string, $i, 1);
}
}
return $str. ';
}else{
return $string;
}
}
|