P.Henderson P.Henderson - 2 years ago 154
Perl Question

Perl HTML Encoding Named Entities

I would like to encode 'special chars' to their named entity.

My code:

use HTML::Entities;
print encode_entities('“');

Desired output:


And not:


Does anyone have an idea? Greetings

Answer Source

Perl doesn't know the encoding of your source file. If you include any special characters, you should always save it with UTF-8-encoding and put

use utf8;

at the top of your code. This will make sure your string literals contain codepoints, not just bytes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download