1HTML::HTML5::Entities(3U)ser Contributed Perl DocumentatiHoTnML::HTML5::Entities(3)
2
3
4

NAME

6       HTML::HTML5::Entities - drop-in replacement for HTML::Entities
7

SYNOPSIS

9        use HTML::Entities;
10
11        my $enc = encode_entities('fish & chips');
12        print "$enc\n";   # fish & chips
13
14        my $dec = decode_entities($enc);
15        print "$dec\n";   # fish & chips
16

DESCRIPTION

18       This is a drop-in replacement for HTML::Entities, providing the
19       character entities defined in HTML5. Some caveats:
20
21       ·   The implementation is pure perl, hence in some cases slower,
22           especially decoding.
23
24       ·   It will not work in Perl < 5.8.1.
25
26   Functions
27       "decode_entities($string, ...)"
28           This routine replaces HTML entities found in the $string with the
29           corresponding Unicode character. If multiple strings are provided
30           as arguments they are each decoded separately and the same number
31           of strings are returned.
32
33           If called in void context the arguments are decoded in-place.
34
35           This routine is exported by default.
36
37       "_decode_entities($string, \%entity2char)"
38       "_decode_entities($string, \%entity2char, $expand_prefix)"
39           This will in-place replace HTML entities in $string. The
40           %entity2char hash must be provided. Named entities not found in the
41           %entity2char hash are left alone. Numeric entities are always
42           expanded.
43
44           If $expand_prefix is TRUE then entities without trailing ";" in
45           %entity2char will even be expanded as a prefix of a longer
46           unrecognized name.
47
48            $string = "foo&nbspbar";
49            _decode_entities($string, { nb => "@", nbsp => "\xA0" }, 1);
50            print $string;  # will print "foo bar"
51
52           This routine is exported by default.
53
54       "encode_entities($string)"
55       "encode_entities($string, $unsafe_chars)"
56           This routine replaces unsafe characters in $string with their
57           entity representation. A second argument can be given to specify
58           which characters to consider unsafe (i.e., which to escape). This
59           may be a regular expression.
60
61           If called in void context the string is encoded in-place.
62
63           This routine is exported by default.
64
65       "encode_entities_numeric($string)"
66           This routine works just like encode_entities, except that the
67           replacement entities are always numeric.
68
69           This routine is not exported by default.
70
71       "num_entity($string)"
72           Given a single character string, encodes it as a numeric entity.
73
74           This routine is not exported by default.
75
76       The following functions cannot be exported. They behave the same as the
77       exportable functions.
78
79       "HTML::Entities::decode($string, ...)"
80       "HTML::Entities::encode($string)"
81       "HTML::Entities::encode($string, $unsafe_characters)"
82       "HTML::Entities::encode_numeric($string)"
83       "HTML::Entities::encode_numeric($string, $unsafe_characters)"
84       "HTML::Entities::encode_numerically($string)"
85       "HTML::Entities::encode_numerically($string, $unsafe_characters)"
86
87   Variables
88       $HTML::HTML5::Entities::hex
89           This variable controls whether numeric entities will use
90           hexadecimal or decimal notation. It is TRUE (hexadecimal) by
91           default, but can be set to FALSE.
92
93           It only affects the encoding functions. Decoding always understands
94           both notations.
95
96       %HTML::HTML5::Entities::char2entity
97       %HTML::HTML5::Entities::entity2char
98           There contain the mapping from all characters to the corresponding
99           entities (and vice versa, respectively). These variables may be
100           exported.
101
102           Note that %char2entity is a more conservative set of mappings,
103           intended to be safe for serialising strings to HTML4, HTML5 and
104           XHTML 1.x. And for hysterical raisins, %entity2char does not
105           include the leading ampersands, while %char2entity does.
106

BUGS

108       Please report any bugs to
109       <http://rt.cpan.org/Dist/Display.html?Queue=HTML-HTML5-Entities>.
110

SEE ALSO

112       HTML::Entities, HTML::HTML5::Parser, HTML::HTML5::Writer.
113

AUTHOR

115       Toby Inkster <tobyink@cpan.org>.
116
118   Encoding and Decoding Functions
119       Copyright (c) 1995-2006 by Gisle Aas.
120
121       Copyright (c) 2012 by Toby Inkster.
122
123       This is free software; you can redistribute it and/or modify it under
124       the same terms as the Perl 5 programming language system itself.
125
126   Entity Tables
127       Copyright (c) 2004-2007 by Apple Computer Inc, Mozilla Foundation, and
128       Opera Software ASA.
129
130       Copyright (c) 2007-2011 by Wakaba <w@suika.fam.cx>.
131
132       Copyright (c) 2009-2012 by Toby Inkster <tobyink@cpan.org>.
133

DISCLAIMER OF WARRANTIES

135       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
136       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
137       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
138
139
140
141perl v5.30.0                      2019-07-26          HTML::HTML5::Entities(3)
Impressum