This function is what knowledge in PHP, what is the function of it?
Batting practice encounters the following function, which has never been touched.
First, what is the knowledge in PHP? File processing? or a binary?
Second, please comment from the beginning to the end. Why use 00XX, memory code.
PHP Code
function Js_unescape ($str) { $ret = '; $len = strlen ($STR); for ($i = 0; $i < $len; $i + +) { if ($str [$i] = = '% ' && $str [$i +1] = = ' U ') { $val = Hexdec (Subs TR ($STR, $i +2, 4)); if ($val < 0x7f) $ret. = Chr ($val); else if ($val < 0x800) $ret. = Chr (0xc0| ( $val >>6). Chr (0x80| ( $val &0x3f)); else $ret. = Chr (0xe0| ( $val >>12). Chr (0x80| ( ($val >>6) &0x3f). Chr (0x80| ( $val &0x3f)); $i + = 5; } else if ($str [$i] = = '% ') { $ret. = UrlDecode (substr ($str, $i, 3)) ; $i + = 2; } else $ret. = $str [$i]; } return $ret; }
------Solution--------------------
Decoding, PHP version of the unescape (JS)
JS in the Escape method returns a string value (Unicode format) that contains the charstring content, all spaces, punctuation, accents to
and other non-ASCII characters are replaced with%XX encoding, where xx equals the hexadecimal number that represents the character. For example, a space returns "%20"
Characters with values greater than 255 are stored in%UXXXX format.
Greater than 0x7f is the Chinese character, the high level is 1, bitwise operation, the core operation is to decode the Chinese characters
0x800 I did not understand, and the right to translate 6 bits and or not on the out of something, is to think about Ah, who can give a detailed description of a Chinese character encoding operation AH
------Solution--------------------
In
Ucs-2
4e2d
01001110 00101101
Utf-8
E4b8ad
11100100 10111000 10101101
To Franzhong
Since you know greater than 0x7f is a Chinese character, then how do not know less than 0x800 is not the Chinese character