What is the knowledge of this function in PHP and what is its function? The following function has never been used. First, what is PHP knowledge? File processing? Or binary? Second, note it from the beginning to the end. Why have we used the memory code 00XX. PHPcodefunctionjs_unescape ($ str) {$ ret; $ lenstrlen ($ str what is this function in PHP? what is its function?
The following function has never been used.
First, what is PHP knowledge? File processing? Or binary?
Second, note it from the beginning to the end. Why have we used the memory code 00XX.
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(substr($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 is considered as the php version of unescape (js)
In js, the escape method returns a string that contains the charstring content (in Unicode format ).
And other non-ASCII characters are replaced by % xx encoding, where xx is equal to the hexadecimal number of the character. For example, "% 20" is returned by a space"
The characters with a value greater than 255 are stored in % uxxxx format.
If the value is greater than 0x7f, it is a Chinese character with a high position of 1 and a bitwise operation. The core operation is to decode Chinese characters.
I didn't understand 0x800 either, or I had to translate six or more characters to the right, so I had to think about it. who can explain how to encode a Chinese character?
------ Solution --------------------
Medium
UCS-2
4e2d
01001110 00101101
UTF-8
E4b8ad
11100100 10111000 10101101
To franzhong
Since you know that the value greater than 0x7f is a Chinese character, how can you not know that the value less than 0x800 is not a Chinese character?