Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:
Here's the situation:
I have an HTML form. When its contents are submitted to a perl script, any non-ASCII characters come out wrongly encoded, for instance if I type 'I like Beyoncé' it comes out in my script as 'I like Beyoncé'
The script does some other stuff, AJAX was involved at one point, but I have now reduced it to a simple (POST or GET) request to this script:
use CGI::Simple; my $q = CGI::Simple->new(); print "Content-type: text/plain\n\n"; print $q->param('text');
And if the 'text' parameter contains anything double-byte/UTF-8, I get that output.
Things I have tried:
But still the problem persists. What else can I do?
Confusingly, this page: https://www.i18nqa.com/debug/utf8-debug.html seems to suggest my errant character, é turning into é is caused by Windows-1252 encoding, a.k.a. ISO 8859-1, but this is nothing to do with Windows. It's happening on OS X for a start.
TIA, fellow monks
SOLVED: This is what worked:
use Encode; print Encode::decode_utf8($q->param('text'))
I guess I just have to accept that when the text leaves URL A it might be UTF-8 but there's no way to tell page B that, and I will always have to decode it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I convince my Perl script that UTF-8 from an HTML form really is UTF-8?
by haj (Vicar) on Mar 10, 2020 at 22:09 UTC | |
by Cody Fendant (Hermit) on Mar 11, 2020 at 19:28 UTC | |
by haj (Vicar) on Mar 11, 2020 at 21:24 UTC | |
|
Re: How do I convince my Perl script that UTF-8 from an HTML form really is UTF-8?
by graff (Chancellor) on Mar 11, 2020 at 01:00 UTC | |
by Cody Fendant (Hermit) on Mar 11, 2020 at 19:45 UTC | |
|
Re: How do I convince my Perl script that UTF-8 from an HTML form really is UTF-8? (reproducible)
by Anonymous Monk on Mar 10, 2020 at 22:13 UTC |