This function is the common sense in PHP, what is its function

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.