in reply to Re^2: sring encode problem (hexadecimal)
in thread sring encode problem (hexadecimal)

From the documentation of HTML::Entities:
encode_entities_numeric( $string ) encode_entities_numeric( $string, $unsafe_chars ) This routine works just like encode_entities, except that t +he replacement entities are always "&#xhexnum;" and never "&en +tname;". For example, "encode_entities("r\xF4le")" returns "rô +le", but "encode_entities_numeric("r\xF4le")" returns "rôle". This routine is not exported by default. But you can alway +s export it with "use HTML::Entities qw(encode_entities_numeric);" o +r even "use HTML::Entities qw(:DEFAULT encode_entities_numeric);"

Replies are listed 'Best First'.
Re^4: sring encode problem (hexadecimal)
by courierb (Novice) on Jan 20, 2011 at 05:16 UTC
    well. i am not so understand the doc as English is not my native language.
    here is my code to test it again and it works .
    It do produce string "€" start from "&#x" while it has 5 digits which is not 7 byte string .
    #use HTML::Entities; use HTML::Entities"encode_entities_numeric"; $string="€"; # ("€" expected out put result after encoding) $encoded = encode_entities_numeric($string); print $encoded;





    while when i test it in this way
    #use HTML::Entities; use utf8 ; ########### use HTML::Entities"encode_entities_numeric"; $string="€"; # ("€" expected out put result after encoding) $encoded = encode_entities_numeric($string); print $encoded;
    it print out character "€" itself as if there is no encoding happened.
    what should i do??
    Cheers


      Works for me:
      #!/usr/bin/perl use 5.010; use strict; use warnings; use HTML::Entities qw[encode_entities_numeric]; my $string = "\x{20AC}"; my $encoded = encode_entities_numeric $string; say $encoded; __END__ €
        Hi JavaFan

        Thank you for your code. you are right. now it is work indeed
        however in your code
        line 7 my $string = "\x{20AC}";
        Is "\x{20AC}" equvalent to "€";??


        why do you use my $string = "\x{20AC}"; instead of $string = "€";
        would it be possible to use
        my $string = "€"; ??
        as i would pass value from form to it . these value would be any double byte character.




        Many thanks

Re^4: sring encode problem (hexadecimal)
by Anonymous Monk on Jan 19, 2011 at 13:24 UTC
    JavaFan i really appreciate y your assitance.
    however i still cant get it work

    could you give me a sample code to prove it ?
    as i have tested it however i got error as i said above.


    cheers



      could you give me a sample code to prove it ?
      The code you need is right there in the part of the documentation I quoted.