Does anyone know what encoding Google Chrome uses for encoding the URL?
Encoding happens when we try to copy the URL from Google's search box (Omnibox).
I have pasted the following URL:
www.bing.com/search?q=이윤희&go=&qs=n&form=QBLH&filt=all&pq=이윤희&sc=0-0&sp=-1&sk=
into Google search then copy the same URL back from the search box and it becomes this:
http://www.bing.com/search?q=%EC%9D%B4%EC%9C%A4%ED%9D%AC&go=&qs=n&form=QBLH&filt=all&pq=%EC%9D%B4%EC%9C%A4%ED%9D%AC&sc=0-0&sp=-1&sk=
I want to know what encoding they are using.
A space is assigned number 32, which is 20 in hexadecimal. When you see “%20,” it represents a space in an encoded URL, for example, http://www.example.com/products%20and%20services.html.
So you can test if the string contains a colon, if not, urldecode it, and if that string contains a colon, the original string was url encoded, if not, check if the strings are different and if so, urldecode again and if not, it is not a valid URI.
Browsers automatically encode the URL i.e. it converts some special characters to other reserved characters and then makes the request.
That's standard percent URL encoding, in this case of UTF-8 encoded text. A URL cannot contain non-ASCII characters (actually, a subset thereof, different subsets for different parts of the URL). You cannot actually have "이윤희" in a URL. To embed arbitrary characters, you can percent encode them. This simply takes a single byte and encodes its hex value as %xx
. The UTF-8 byte representation of "이윤희" is EC 9D B4 EC 9C A4 ED 9D AC
, which is exactly what you're seeing in the URL.
The URL is always this way, it's not Chrome doing it when you copy. On the contrary, if the URL displays as www.bing.com/search?q=이윤희&...
, that's Chrome being nice and displaying the URL decoded for you.
See What every web developer must know about URL encoding.
In PHP this can be replicated with rawurlencode
:
echo rawurlencode('이윤희'); // (assuming UTF-8 encoded source code)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With