Conversion of numbered html entities
use HTML::Entities::Numbered;
$html = 'Hi Honey<b>♥</b>';
# convert named HTML entities to numbered (decimal) $decimal = name2decimal($html); # Hi Honey<b>♥</b>
# to numbered (hexadecimal) $hex = name2hex($html); # Hi Honey<b>♥</b>
$content = 'Copyright © Larry Wall';
# convert numbered HTML entities (decimal) to named $name1 = decimal2name($content); # Copyright © Larry Wall
$content = 'Copyright © Larry Wall'; # convert numbered HTML entitites (hexadecimal) to named $name2 = hex2name($content); # Copyright © Larry Wall
$xml = '"Give me ¥10,000" > cherie♠';
# convert named HTML entities to numbered # except valid XML entities (decimal) $decimal = name2decimal_xml($xml); # "Give me ¥10,000" # > cherie♠
# to numbered except valid XML entities (hexdecimal) $hex = name2hex_xml($xml); # "Give me ¥10,000" # > cherie♠
HTML::Entities::Numbered is a content conversion filter for named \s-1HTML\s0 entities (symbols, mathmetical symbols, Greek letters, Latin letters, etc.). When an argument of \*(C`name2decimal()\*(C' or \*(C`name2hex()\*(C' contains some nameable \s-1HTML\s0 entities, they will be replaced to numbered \s-1HTML\s0 entities. And when an argument of \*(C`name2decimal_xml()\*(C' or \*(C`name2hex_xml()\*(C' contains some nameable numbered \s-1HTML\s0 entities, they will be replaced to numbered \s-1HTML\s0 entities except valid \s-1XML\s0 entities (the excepted \*(L"valid \s-1XML\s0 entities\*(R" are the following five entities: \*(C`<\*(C', \*(C`>\*(C', \*(C`&\*(C', \*(C`"\*(C', \*(C`'\*(C'). By the same token, when an argument of \*(C`decimal2name()\*(C' or \*(C`hex2name()\*(C' contains some nameable numbered \s-1HTML\s0 entities, they will be replaced to named \s-1HTML\s0 entities.
(the exception \*(L"valid \s-1XML\s0 entities\*(R" means the following five entities: \*(C`<\*(C', \*(C`>\*(C', \*(C`&\*(C', \*(C`"\*(C', \*(C`'\*(C')
On version 0.03, the entities hash table is imported from HTML::Entities (with obsolete class \*(C`HTML::Entities::Numbered::Extra\*(C' for older releases of Perl). At the moment, 0.04 (or later) is included HTML::Entities::Numbered::Table to import \s-1HTML\s0 entities table, and thereby we do not need to have HTML::Entities (included in HTML::Parser distribution).
This may be also useful for making valid \s-1XML\s0 (corrects the undefined entity references, and enhanced by addition of functions conform to the \s-1XML\s0).
Following all functions are exported by default.
Some included named \s-1HTML\s0 entities in argument of \*(C`name2decimal()\*(C' will be replaced to decimal numbered \s-1HTML\s0 entities.
Some included named \s-1HTML\s0 entities in argument of \*(C`name2hex()\*(C' will be replaced to hexadecimal numbered \s-1HTML\s0 entities.
Some include decimal numbered \s-1HTML\s0 entities in argument of \*(C`decimal2name()\*(C' will be replaced to named \s-1HTML\s0 entities (If they're nameable).
Some include hexadecimal numbered \s-1HTML\s0 entities in argument of \*(C`hex2name()\*(C' will be replaced to named \s-1HTML\s0 entities (If they're nameable).
Some included named \s-1HTML\s0 entities in argument of \*(C`name2decimal_xml()\*(C' will be replaced to decimal numbered \s-1HTML\s0 entities except valid \s-1XML\s0 entities.
Some included named \s-1HTML\s0 entities in argument of \*(C`name2hex_xml()\*(C' will be replaced to hexadecimal numbered \s-1HTML\s0 entities except valid \s-1XML\s0 entities.
If you'd prefer not to import them functions into the caller's namespace, you can call them as below:
use HTML::Entities::Numbered ();
$decimal = HTML::Entities::Numbered::name2decimal($str); $hex = HTML::Entities::Numbered::name2hex($str); $named1 = HTML::Entities::Numbered::decimal2name($str); $named2 = HTML::Entities::Numbered::hex2name($str); $decimal = HTML::Entities::Numbered::name2decimal_xml($str); $hex = HTML::Entities::Numbered::name2hex_xml($str);
Koichi Taniguchi <[email protected]>
Develop triggered by \s-1IKEBE\s0 Tomohiro <[email protected]>
Many thanks to Tatsuhiko Miyagawa <[email protected]>
Copyright (c) 2004 Koichi Taniguchi. Japan. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
HTML::Entities, <http://www.w3.org/TR/REC-html40/sgml/entities.html>