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”, you could not construct a URL such as:
http://www.httprecipes.com/1/test.php?name=John Smith
The above URL is invalid because spaces are not allowed in a URL. To put a space into a URL, express the URL as follows:
http://www.httprecipes.com/1/test.php?name=John%20Smith
As you can see, the above URL contains the characters “%20” where the space is. 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.
The space character, however, is special. It also has a second way that it can be represented. Spaces can be represented with the plus (+) character. Therefore, it would also be valid to represent the above URL as:
Of course, this means the only way to represent a “+” symbol itself 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.




