Torsten Förtsch > TX > TX::Escape

Download:
TX-0.09.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

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 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 );
$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

 &quot;, &lt;, &gt; and &amp;

If the optional flag parameter is true also whitespace characters are escaped. Each space is replaced by &nbsp;, newlines by <br />.

In a future version the $flag parameter is probably renamed into $tabwidth and html_esc will handle tab characters as well.

SEE ALSO ^

TX

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.

syntax highlighting: