in reply to Passing unicode via html forms

use 5.008; use Encode qw(decode_utf8); my $s = decode_utf8(param('name'));

Replies are listed 'Best First'.
Re^2: Passing unicode via html forms
by Baz (Friar) on Sep 25, 2004 at 20:56 UTC
    #!/usr/bin/perl -w use CGI; use CGI::Carp "fatalsToBrowser"; use HTML::Template; use Encode; my $cgi = new CGI; my $sym = $cgi->param('cs') || ''; my $euro = "\x{20AC}"; my $charset = "utf-8"; Encode::_utf8_on($sym); print $cgi->header(-charset => $charset), $cgi->start_html ( -encoding => $charset, -head => $cgi->meta({-http_equiv => "Content-Type", -content => "text/html; charset=".$charset}), -title => "Euro", ), $sym, $cgi->br, UnicodeString(($sym)), $cgi->br, UnicodeString($euro),$cgi->br; if($euro eq $sym) { print "match"; } print $cgi->end_html; sub UnicodeString{ my $str; join("", map { $str .= sprintf("0x%04X ", $_) # \x{...} } unpack("U*", $_[0])); # unpack Unicode characters return $str; }
    Call as: http://baz.perlmonk.org/euro.cgi?cs=%E2%82%AC