![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
Printable CharactersLike most other Internet protocols, URLs were originally designed to ensure that they could be sent via e-mail. Most older mail systems were capable of recognizing only 7-bit characters, so the characters used in a URL must con- form to that. However, even some of these characters have a special meaning in a URL. For example, the ampersand (&) is used to separate the parameters in the query string. But you will encounter many occasions when you have to send ampersands and plus signs and equal signs and even 8-bit, non-ASCII characters in a URL. How can it be done? The solution in the URL scheme of things is to encode these special characters in the form %nn where the percent sign (%) indicates that the next two characters are the hexadecimal value of the actual, encoded character. A good example of this is the question mark (?) that begins the query string in our example: perl.bat?LastName=Jones&FirstName=John&Address=123+Any+Street Again, this character has a special meaning in the URL because it indicates that perl.bat should be run with the arguments that follow it. If a literal question mark is included in any of the arguments, it is encoded as %26 because 26 is the hexadecimal code for a question mark in the ASCII table. Table 5.2 shows the other printable ASCII characters that have a special meaning in a URL and therefore will be encoded by the browser.
Any control characters that wind up in a URL will be encoded, too. Because you, as the CGI programmer, are sitting at the other end of this scheme, you dont have to deal with encoding characters. The rule for you will be simple: Any time you encounter a percent sign in a query string, you may assume that the next two characters are the hexadecimal code of the character that is really intended to be there.
You dont have to be too concerned with the actual ASCII values of the characters, although every programmer usually has an ASCII table handy for reference. Perl has a number of handy tricks for turning hexadecimal values into characters, as youll soon see. What youll have to do at your end is recognize an encoded character, strip off the percent sign, and send the remaining number to a Perl function that will translate it for you.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |