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

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


Replies are listed 'Best First'.
Re^5: sring encode problem (hexadecimal)
by JavaFan (Canon) on Jan 20, 2011 at 09:59 UTC
    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

        They are equivalent. I prefer to use \x{20AC} (and \x escapes in general) because that's encoding agnostic. If you write $string = "€";, I cannot see whether that's UTF-8, or perhaps ISO-8856-15.