You are here

Encoding Special Characters into a URL

    URLs can contain a wide variety of characters; however, there are only certain characters that you can put directly into a URL. For example, you cannot put a space into a URL. If you wanted to pass the value “John Smith” to the variable “name”, do not construct a URL such as: Smith

    The above URL is invalid because spaces are not allowed in a URL. To put a space into a URL, write the URL as:

    The above URL contains the characters “%20” instead of a space. This is because a space is ASCII code 32. The decimal number “32” is “20” in hexadecimal. Any ASCII code, from 0 (hexadecimal 0) to 255 (hexadecimal FF) can be represented this way.

    However, the space character is special. There is a second way that it can be represented. Spaces can be represented with the plus (+) character. Therefore, it is valid to represent the above URL as:

    This means the only way to represent a “+” symbol in a URL is to use the hexadecimal ASCII code “%2B”. Now that you understand how to construct a URL, it is time to see how to use them. This will be covered in the next section.


Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer