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
A .. Z, a .. z, 0 .. 9, -, _, ., !, ~, *, ', (, ) and /
replaced by their %HH notation where HH 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 );
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 );
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 and html_esc will handle tab characters as well.
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.