Home > Backend Development > PHP Tutorial > Custom interception of Chinese without garbled characters

Custom interception of Chinese without garbled characters

WBOY
Release: 2016-07-25 08:47:58
Original
887 people have browsed it
Custom interception of Chinese without garbled characters
  1. 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
  2. $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
  3. for($i=0;$i<$strlen;$i++) {
  4. 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
  5. $tmpstr.=substr($str,$i,2) ; //Each two characters are taken out and assigned to the variable $tmpstr, which is equal to one Chinese character
  6. $i++; //The variable increases by 1
  7. }
  8. else
  9. $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
  10. }
  11. return $tmpstr; //Return the string
  12. }
Copy code


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template