In PHP it's as simple as htmlspecialchars
, how to do it in Perl?
Asked
Active
Viewed 1,557 times
1

Je Rog
- 5,675
- 8
- 39
- 47
-
If you are generating HTML using one of the templating modules (e.g.: Template Toolkit, HTML::Mason etc) then the template system will provide a way to escape the output as required. – Grant McLean Aug 02 '11 at 21:49
1 Answers
7
Use the HTML::Entities module.
use HTML::Entities;
my $input = "<em>TEST</em>";
print(encode_entities($input));

Paolo Rovelli
- 9,396
- 2
- 58
- 37

spraff
- 32,570
- 22
- 121
- 229
-
2Or the `html` filter in Template-Toolkit (hint: Using a template module is a good idea if you are generating HTML). – Quentin Aug 01 '11 at 15:43
-
Nope,it's different according to this answer, the answer prefers `htmlspecialchars` to `htmlentities`: http://stackoverflow.com/questions/46483/htmlentities-vs-htmlspecialchars/46491#46491 – Je Rog Aug 01 '11 at 15:56
-
2@Je Rog `HTML::Entities` is equivalent to both of those PHP functions, but its default behavior is like `htmlspecialchars`. – hobbs Aug 01 '11 at 16:45