Thank you all for your suggestions but I don't feel I'm any closer with this problem, partly my own fault for not being clear what I want. (Which i'm figuring out as I puzzle it out.) I'd like the text/data to be portable to other applications that can read HTML.
I did figure out (thanks poj) that I can set the encoding in the HTML page to have it display correctly in the browser. But if that text gets posted to another page or app I don't necessarily have control over its page encoding.
SO what I really want is to HTML encode those characters. But when I try HTML::Encode: for, say, the smart apostrophe:
use HTML::Entities; my($text) = "Krens 89th birthday"; print encode_entities($text), $/;
that one character gets converted to three HTML entities:
Kren’s 89th birthday
which displays a lot of garbage in the browser.
So I'm lost as to what's going on or how to resolve it. Perl is rendering the JSON string as a smart quote but HTML::Encode is improperly encoding it.
So far my best solution seems to be:
$event{'desc'} =~ s//\&\#39\;/g; $event{'desc'} =~ s//-/g; $event{'desc'} =~ s// - /g; $event{'desc'} =~ s//'/g; $event{'desc'} =~ s/'/'/g; $event{'desc'} =~ s//"/g; $event{'desc'} =~ s//"/g;
but of course that only handles characters I'm aware of.
Thoughts? Thanks for your patience.
Scott
In reply to Re: special characters in parsed json rendering badly in browser
by slugger415
in thread special characters in parsed json rendering badly in browser
by slugger415
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |