#!/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~
~;
#--// content -------------------------------
return ($content);
}