View Full Version : illegal characters in CGI
agnieszka
September 24th, 2001, 22:13
hi, i was wondering if someone could give me a list of characters before which i need to put a backslash (" \ ") for CGI when 'printing' to a page (sorry, i don't know the technical words when talking about CGI, i'm new to it and only editing scripts, not writing them from scratch).
eg..
print "<html><head><title>ag's page - <title>\n";
print "<meta http-equiv=content-type content=\"text/html; text/css1; charset=iso-8859-2\">\n";
i need it before a " and what else??
niv
September 24th, 2001, 22:29
just look up meta-characters in any perl reference book. you should find the entire list.
jm4n
September 25th, 2001, 00:30
The only characters you should need to escape are quotes (only because you are inside quotes), a dollar sign and @ (since you are within double quotes).
If you were within a single quote, you'd only have to escape single quotes. However, variables would not be expanded.
Personally I'd use a different quoting, eg:
print qq(This is text to be printed. "Quotes" are okay.);
Or, for single quoting:
print q(This is "single quoting". $dollars and @at don't need escaping. Neither do (parenthesies) as long as they're matched.);
There's also here docs. Not to mention quotemeta(), and many other tricks...
Best bet is to pick up any good Perl book (the "camel book" published by Oreilly is the best) and truly learn how Perl works.
niv
September 25th, 2001, 09:40
print<<STUFF;
lalalalala
STUFF
is nice too :)
agnieszka
September 25th, 2001, 19:53
thanks for your help,. this ought to get me started for now... :-)
jm4n
September 26th, 2001, 00:44
print<<STUFF;
lalalalala
STUFF
That would be a "here document", as I mentioned above :)
I personally use ~ for quoting. I also indent the output lines along with the rest of the code for neatness (here docs require the terminator to be on the beginning of a line, throwing off indentation).
I was going to give an example, but this board doesn't preserve spacing, thus the indentation is lost... but you get the idea.
agnieszka
September 27th, 2001, 01:14
would it matter if i escaped normal characters?
jm4n
September 27th, 2001, 01:53
You can safely escape any character that is not a letter or number *if you are in double-quoting* In single quoting, the text will be printed as-is, including the backslashes.
Letters/numbers have special meanings when preceded with a backslash (eg, "\n" is newline, "\0" is a NULL character).
The quotemeta() function does exactly what you're looking for -- it escapes all non-alpha-numeric characters (or "meta characters").
As I mentioned before, my best advice would be to pick up a good Perl book (or spend some time reading the perl documentation (http://www.basiclinuxhost.com/docs/Perl-5.6.1/) and familiarize yourself with the language itself. These types of questions will answer themselves once you've become familiar with Perl. It's a language definately worth learning.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.