http://www.w3schools.com/tags/ref_urlencode.asp
Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.
But both space, /, % are part of the ASCII character set, so why encode them in the first place? What characters should be encoded?
As noted, spaces are not valid in URLs. Most browsers orlencode them automatically. However...
The page you linked to has an example using the word "Günter" in the "Try me" section. If the word "Günter" were sent as a querystring parameter, it wouldn't work. as the "ü" is not in the standard ASCII character set.
It's meant to be used when there are potentially non-ASCII characters. An example might be when using data from a database to create a hyperlink. Suppose the code creates a link to a user profile page. Unencoded, mine would be:
<a href="profile/?username=David Stratton">Your profile</a>
while Günter's would be
<a href="profile/?username=Günter">Your profile</a>
Mine, most browsers could handle. Günter's, probably not.
Encoded, these would become
<a href="profile/?username=David%20Stratton">Your profile</a>
and
<a href="profile/?username=G%FCnter">Your profile</a>
which are valid URLs.
(Please forgive the fact that most well-designed systems wouldn't pass a username in a parameter like that. This was just a sample to clarify the concept.)
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