NAME
TX::Escape - simple HTML escaping routines
SYNOPSIS
use TX::Escape qw/:all/;
my $escaped=url_esc( $string );
my $plain=url_unesc( $escaped );
print html_esc( $text, $flag );
DESCRIPTION
This module contains 3 simple functions that are often used in combination with HTML processing.
- $escaped=url_esc $string
-
returns
$string
with all characters except ofA .. Z, a .. z, 0 .. 9, -, _, ., !, ~, *, ', (, ) and /
replaced by their
%HH
notation whereHH
are 2 hexadecimal digits.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:use Encode (); $escaped=url_esc Encode::encode( 'utf-8', $string );
- $plain=url_unesc $escaped
-
This is just the reverse of
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 );
- $html=html_esc $text, $flag
-
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 />
.In a future version the
$flag
parameter is probably renamed into$tabwidth
andhtml_esc
will handletab
characters as well.
SEE ALSO
AUTHOR
Torsten Foertsch, <torsten.foertsch@gmx.net<gt>
COPYRIGHT AND LICENSE
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.