URL-Encoding

URL-encoding is a simple method of encoding which converts spaces and other characters which may confuse the program reading the form data. Since '=' and '&' are used for special purposes in the form data [see the section called Form-Data Format], the program wouldn't know the difference between the user's '&' [or '='] and the special '&' [or '=']. Therefore, all '&'s, '='s, spaces and some other characters are converted by URL-Encoding, however the majority of characters are left alone.

Spaces are converted to "+"; most alphabetical and numerical characters are left alone. Other characters are converted to their ASCII value preceded by a '%' character [ie: "%nn" where 'nn' is the ASCII value of the character in hexadecimal]. For instance, since <space> is converted to '+', a '+' in the user's input would be converted to '%2B', since 2B is the hexadecimal equivalent decimal 43, the ASCII value of the character '+'.

For instance, the string "2 + 2 = 4" would be URL-Encoded to read:

2+%2B+2+%3D+4
since '+' is <space>, %2B is '+' and %3D is '='.

The URL decoding process is relatively straightforward, but it is usually more useful to use a pre-written library [such as 'cgi-lib.pl'] to do the conversion and decoding.