in reply to sring encode problem (hexadecimal)

search HTML::Entities docs, it looks to me that you are searching for this method:

encode_entities_numeric( $string, $unsafe_chars )

Replies are listed 'Best First'.
Re^2: sring encode problem (hexadecimal)
by courierb (Novice) on Jan 19, 2011 at 11:38 UTC
    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


      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


        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