jabowery has asked for the wisdom of the Perl Monks concerning the following question:

There's got to be a better way:
$html=~s/(.)/ord($1)>255?encode_entities($1):$1/ge;

Replies are listed 'Best First'.
Re: Encode only wide char entities?
by Your Mother (Archbishop) on Mar 09, 2012 at 20:59 UTC

    You read the docs, right? :P HTML::Entities.

    and this would only encode non-plain ascii: $encoded = encode_entities($input, '^\n\x20-\x25\x27-\x7e');
Re: Encode only wide char entities?
by ikegami (Patriarch) on Mar 09, 2012 at 22:31 UTC
    Why would someone escape more than &<>'" these days? Isn't your HTML's charset UTF-8?
      I'm using utf8 but I'm getting "wide chars" from nasty M$ programs.

      What I was missing was the unicode range syntax:

      encode_entities($_,'\x{0100}-\x{FFFF}')

      I suppose I could convert everything to utf8 that comes in but I wanted to expose the unicode as entities in the source.

        You SAY you're using UTF-8, but you forgot to actually encode to UTF-8. You probably need something like
        binmode(STDOUT, ":encoding(UTF-8)");
      some webadmins configure apache to deliver iso-latin and deny .htaccess.

      no chance to use utf8 then.

      I had this case just a week ago...

      Cheers Rolf

        And Perlmonks uses cp1252. I'm assuming that's not the case here until he tells me otherwise.