http://www.perlmonks.org?node_id=1039095


in reply to HTML::Entities encode_entities for perlmonks [ ]

Using the HTML::Entities documentation:

#!/usr/bin/env perl -l use strict; use warnings; use utf8; binmode(STDOUT => ':utf8'); use HTML::Entities; my $unsafe_chars = "<&>'\"[]\200-\377"; my $string = "<[Here's my \"2¢\" worth]>"; print $string; print encode_entities($string, $unsafe_chars);

Output:

$ pm_html_ent_plus_brackets.pl <[Here's my "2¢" worth]> &lt;&#91;Here&#39;s my &quot;2&cent;&quot; worth&#93;&gt;

Update: Oops! just noticed &Acirc; in the output (just before &cent;). Fixed by adding:

use utf8; binmode(STDOUT => ':utf8');

-- Ken