in reply to sring encode problem (hexadecimal)

I think you want (untested):
s/([^\x00-\xFF])/sprintf "&#x%x;", $1/eg; # Encode s/&#x(\p{AHex}+);/chr hex $1/eg; # Decode

Replies are listed 'Best First'.
Re^2: sring encode problem (hexadecimal)
by courierb (Novice) on Jan 19, 2011 at 11:44 UTC
    Hi JavaFan


    It seems it is non working. i wil return a blank (nothing return)
    #!/usr/bin/perl $string="€"; $string = s/([^\x00-\xFF])/sprintf "&#x%x;", $1/eg; # Encode print $string;


    Anyway thanks for the reply Have a nice day







      Use a bind operator (=~) instead of an assignment operator (=).
        Thanks for the enlightment.
        Use a bind operator (=~) instead of an assignment operator (=).

        now it seems print out a utf-8 encoded string.
        while it is not 7 digit in the format of "& #x20AC;" (which is 7 digit)


        Thanks again