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

In reply to sring encode problem (hexadecimal) by courierb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.