Know more about URL Encoding

A URL is another word for a web address. URL can be composed of words or an IP address. Most people use the name when surfing, because names are easier to remember than numbers.

Where, URL Encoding is the process of converting string into valid URL format. The valid URL format means that the URL should not contain any unprintable characters or characters with special meaning. URL Encoding helps to represent unambiguous and universally accepted characters for web browsers and servers.

The most commonly encoded character in URL string is the <space> character. You can see plus-sign (+) whenever space in a URL. The plus sign acts as a special character representing that space in a URL.



How could you encode an URL?

To encode a URL, you simply replace the special characters with their encoding string. Nearly most of the special characters encoding begin with a % character followed by hexadecimal number.

If you don't want to do encode items by hand, you can use a pre-define function found in both client and server side languages, such as encodeURI(string) - JavaScript, urlencode(string) - php, encode(string, "UTF-8") - Java etc.

What should be encoded?

Any character that is not an alphabet, a number, or a special character that is being used outside its normal context is going to need to be encoded in your page.


But, If you were writing special character for HTML instead of URL then you need to add an ampersand, you could not use %26. Instead, you would use either "&amp;" or "&#38;", both of which would write out the & in the HTML page when rendered.

Comments