in reply to Re^3: Help for "Cannot decode string with wide characters..." and CGI.pm
in thread Help for "Cannot decode string with wide characters..." and CGI.pm

I get it, that strings shall not be double decoded. I got it to work without errors, but I do not get the UTF-8 displayed.
print $q->header(-charset => 'utf-8'); my $val = $q->param('key'); print utf8::is_utf8($val); exit;
This test gives me 1, which means, the value is UTF-8. But the value is not correctly displayed, just strange signs. Do you know what to do?
  • Comment on Re^4: Help for "Cannot decode string with wide characters..." and CGI.pm
  • Download Code

Replies are listed 'Best First'.
Re^5: Help for "Cannot decode string with wide characters..." and CGI.pm
by Anonymous Monk on Apr 09, 2012 at 01:31 UTC

    But the value is not correctly displayed, just strange signs. Do you know what to do?

    verify everything :)

    all this encoding/decoding stuff just makes sure the bytes sent are proper, it doesn't ensure the HTML/HTTP is interpreted as utf

    You say some browsers are not displaying what you want? Start with the browsers (page info, error console, view source .... ) then move on to http://validator.w3.org/unicorn/

    For CGI.pm

    $ perl -le " use CGI -utf8; my $q = CGI->new; print $q->header, $q->st +art_html " Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> $ perl -le " use CGI -utf8; my $q = CGI->new; print $q->header(qw/ -ch +arset UTF-8 / ), $q->start_html " Content-Type: text/html; charset=UTF-8 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body>

    See also Tutorials: perlunitut: Unicode in Perl, perluniintro, Perl Unicode Essentials