Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Encode only wide char entities?

by jabowery (Beadle)
on Mar 09, 2012 at 20:49 UTC ( [id://958791]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://958791]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found