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

Hi happy.barney Thanks for the reply. Actaully i have test it in that way
but i am unluck to be returned an error
i cant figure out what happened
according to the doc i need to use
encode_entities( $string, $unsafe_chars )


#!/usr/bin/perl use HTML::Entities; $string="€"; $encoded = encode_entities_numeric($string, '<>&"'); print $encoded;

The error was read as :
Undefined subroutine &main::encode_entities_numeric called at 2.cgi line 5.
i was losted. i did the test in winxp.




Cheers


Replies are listed 'Best First'.
Re^3: sring encode problem (hexadecimal)
by JavaFan (Canon) on Jan 19, 2011 at 11:50 UTC
    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&ocirc; +le", but "encode_entities_numeric("r\xF4le")" returns "r&#xF4;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);"
      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="€"; # ("&#x20AC;" 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="€"; # ("&#x20AC;" 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__ &#x20AC;
      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.