Home > Backend Development > PHP Tutorial > Each %XX after urlencode represents a byte?

Each %XX after urlencode represents a byte?

WBOY
Release: 2016-08-04 09:19:30
Original
1195 people have browsed it

After Chinese urlencode, each %XX represents a byte, right?
So the result of urlencode('中') is %XX%XX%XX (utf-8 encoding)

Reply content:

After Chinese urlencode, each %XX represents a byte, right?
So the result of urlencode('中') is %XX%XX%XX (utf-8 encoding)

Yes, in order to solve the problem of unicode taking up too much memory space and unchanged expansion, the utf-8 specification appeared.

  1. For single-byte symbols, the first bit of the byte is set to 0, and the next 7 bits are the Unicode code of this symbol. So for English letters, UTF-8 encoding and ASCII code are the same.

  2. For n-byte symbols (n>1), the first n bits of the first byte are set to 1, the n+1th bit is set to 0, and the first two bits of the following bytes are set to 10. The remaining binary bits not mentioned are all the unicode code of this symbol.

That is to say, the encoding result of UTF-8 is variable length. The utf-8 encoding of the
character in is E4B8AD, so the corresponding urlencode is %E4%B8%AD.

Yes, URL encoding simply represents the data of special symbols and non-ASCII characters in hexadecimal, and then adds a percent sign before each byte (that is, two hexadecimal numbers). For those non-special ASCII characters the URL encoding is itself.

The same Chinese character, if it is GBK encoding, it will be two bytes, if it is UTF-8, it will be three bytes.

Of course, the more troublesome thing is that the URL encoding is confusing. For example, in some places, + is used to represent spaces, and in others, %20 is used. The specific situation still needs to be analyzed in detail. The former corresponds to the function urlencode, and the latter corresponds to rawurlencode. Usually the former is used in form data (including the query in the URL, which is the part after ?), and the latter is used in the URL path (the part after host and before query)

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