http://www.perlmonks.org?node_id=883082

courierb has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'd really appreciate some help here.
for example i have a character "€" (i dont know if the system will filter it out or not)
after encoded it it shows as "€"; know as hexadecimal
here is the javascripts encode and decode code which could conver the character "€" to hexadecimal correctly
just as a reference i copy it below
function encode(str){ return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0). +replace(/(%u)(\w{4})/gi,"&#x$2;")}); } function decode(str){ return str.replace(/&#x/g,'%u').replace(/;/g,''); }
actally i want to know the equevelent of module or code perl which do the same task .
i dig into this forum found a few discussion about it. here is the one related to my question.
http://www.perlmonks.org/?node_id=654948
it seems HTML::Entities is related to my question.
I believe its decode is function well for me. i have tested it
now i try to encode it from a "double bit character" to a string in the foramt of &#xnnn( i just know its name called hexadecimal)
i have tried HTML::Entities but i cant get the expecting result from it.
here is my code. could anyone help me a bit?????
How comes it is functional well in decoding while failed in encoding??
I suspect i missed some thing but i cant find it out. please be note
i wish it's out put be "& #x20ac;" if i key in "€" as the input.
<html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>tf8 Example</title> </head> <body> <form method="post" action="7bit.cgi"> <p>word: <input name="word" type="text"> <input type="submit" name="Submit" value=" submit "> </form> </body> </html> -------7bit.cgi--- #!/usr/bin/perl -w use CGI; use HTML::Entities; use utf8; $query = new CGI; $secretword = $query->param('word'); $remotehost = $query->remote_host(); my $a = $secretword; $a = decode_entities($a); #print encode_entities($a)."\n"; print $query->header( -charset=>'utf-8' ); print "$a";
Thanks in advance Cliff