How can I encode a string for HTML?

Phill Pafford picture Phill Pafford · Jan 20, 2010 · Viewed 24.7k times · Source

I'm looking for a simple way to HTML encode a string/object in Perl. The fewer additional packages used the better.

Answer

friedo picture friedo · Jan 20, 2010

HTML::Entities is your friend here.

use HTML::Entities;
my $encoded = encode_entities( "foo & bar & <baz>" );