| Search perlmeme.org | |
| Home » Faqs » Www » Html encoding |
Some characters have special meanings in HTML, for example, the less-than symbol < and the greater-than symbol >.
If you want these characters to be displayed in your browser you need to use the HTML encoding for them.
For example, instead of < you use the HTML character entity reference < .
The module HTML::Entities provides a simple way of encoding (and decoding) a string:
#!/usr/bin/perl
use strict;
use warnings;
use HTML::Entities;
my $string = 'One < Two';
encode_entities($string);
print "$string\n";
exit 0;
This program produces the following output:
One < Two
The encode_entities() routine replaces characters in your string that
should be displayed as character entities with their entity representation.
perldoc HTML::Entities
HTML::Entities discussed at perladvent.org
HTML 4 Character Entities