#!/usr/bin/perl ################################################################################ # # ################################################################################ use CGI ':standard'; use HTML::Entities; #-- for encode and decode string (%FORM) = (); if ($ENV{'REQUEST_METHOD'} eq "POST") { my ($id); #-- extract the value inside param into %FORM hash foreach $id (param) { $FORM{$id} = param($id); } } # // if post print "Content-Type: text/html; charset=utf-8\n\n"; print "

Encode UTF-8 Chinese Character Input


"; print &input_form; #---------------------------------------------------# #---------------------------------------------------# sub input_form { my ($content) = ""; my ($value) = ""; if ($FORM{'data'} ne "") { $value = $FORM{'data'}; } my ($encoded_value) = ""; my ($process_content) = ""; if ($FORM{'action'} eq "encode") { $encoded_value = $FORM{'encoded_value'}; # !! attempt to do encoding inside perl but the $FORM{'data'} when split, # it become 3 char for Chinese char !! my (@arr) = split(//,$FORM{'data'}); foreach my $c (@arr) { $c = unpack('C*', $c); $process_content .= "$c\n"; } } elsif ($FORM{'action'} eq "decode") { } #-- content --------------------------------- $content = qq~

1. FORM submitted value: $value 2. Encoded value thru JS before form submit: $encoded_value 3. *Try to do encoding inside Perl* $process_content
~; #--// content ------------------------------- return ($content); }