in reply to Re^2: Encoding confusion with CGI forms
in thread Encoding confusion with CGI forms
#!/usr/bin/perl use strict; use Encode; use CGI; $|++; my $c = CGI->new; binmode( STDOUT, ":utf8" ); unless ( () = $c->param ) { print $c->header( -charset => 'utf-8' ), $c->start_html('Character conversion test'), qq{ <form action="/cgi-bin/troy.pl" method="post" enctype="multipart/f +orm-data"> <input type="hidden" name="enc_sniffer" value="\x{df}\x{20ac}"> <textarea name="textInput" rows="25" cols="72"></textarea><p> <input type="submit"> </form>}, $c->end_html; exit; } else { my $enc; my $hidden = $c->param('enc_sniffer'); { use bytes; $enc = ( $hidden eq "\xc3\x9f\xe2\x82\xac" ) ? 'utf8' : ( $hidden eq "\xdf\x80" ) ? 'cp1252' : 'iso-8859-1'; } # decode all param fields here my $qtext = decode( $enc, $c->param('textInput') ); print $c->header( -charset => 'utf-8' ), $c->start_html("Encoding is + $enc"), $enc, " ", $qtext, $c->end_html; }
|
|---|