Custom interception of Chinese without garbled characters
- function chinesesubstr($str,$start,$len) { //$str refers to the string, $start refers to the starting position of the string, $len refers to the length of the string
- $strlen=$start+$len; //Use $strlen to store the total length of the string, that is, from the starting position of the string to the total length of the string
- for($i=0;$i<$strlen;$i++) {
- if(ord(substr ($str,$i,1))>0xa0) { //If the ASCII ordinal value of the first byte in the string is greater than 0xa0, it means Chinese character
- $tmpstr.=substr($str,$i,2) ; //Each two characters are taken out and assigned to the variable $tmpstr, which is equal to one Chinese character
- $i++; //The variable increases by 1
- }
- else
- $tmpstr.=substr($str,$i,1); / /If it is not a Chinese character, take out one character at a time and assign it to the variable $tmpstr
- }
- return $tmpstr; //Return the string
- }
Copy code
|