TX::Escape - simple HTML escaping routines
use TX::Escape qw/:all/; my $escaped=url_esc( $string ); my $plain=url_unesc( $escaped ); print html_esc( $text, $flag );
This module contains 3 simple functions that are often used in combination with HTML processing.
returns $string with all characters except of
$string
A .. Z, a .. z, 0 .. 9, -, _, ., !, ~, *, ', (, ) and /
replaced by their %HH notation where HH are 2 hexadecimal digits.
%HH
HH
This function does not check if the string contains UTF8 characters greater than \x{ff}. If you want to escape those you first have to convert the string into octets:
\x{ff}
use Encode (); $escaped=url_esc Encode::encode( 'utf-8', $string );
This is just the reverse of url_esc.
url_esc
Again, if you want to process UTF8 characters you have to decode the unescaped octet string:
use Encode (); $plain=Encode::decode( 'utf-8', url_esc $escaped );
This function replaces the 4 reserved characters in HTML
", <, >, and &
by their HTML entities
", <, > and &
If the optional flag parameter is true also whitespace characters are escaped. Each space is replaced by , newlines by <br />.
<br />
In a future version the $flag parameter is probably renamed into $tabwidth and html_esc will handle tab characters as well.
$flag
$tabwidth
html_esc
tab
TX
Torsten Foertsch, <torsten.foertsch@gmx.net<gt>
Copyright (C) 2008 by Torsten Foertsch
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install TX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TX
CPAN shell
perl -MCPAN -e shell install TX
For more information on module installation, please visit the detailed CPAN module installation guide.