I got an input file that I need to print directly into an html page.
I did $inputfile =~ s/\\n/<br>/g;
Are there any other special characters I should be aware of maybe other than < and > when printing this $inputfile to html?
You absolutely should use HTML::Escape
instead of doing some ill-conceived hackjob which will cause everyone who deals with your code (you included) to curse your name in the future.
It's simple - install HTML::Escape
via CPAN, then use it thus:
use HTML::Escape qw(escape_html);
my $escaped_string = escape_html($string);
Note that if you want to preserve whitespace formatting you should use a module to do that, as well, such as HTML::FromText
- the above code will not automagically convert line breaks to
tags because that's different completely from escaping unsafe characters to HTML entities.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.