in reply to Change encoding of a string from utf8 to iso-8859-2

Well ... the first thing to realize is that all iso-8859-2 characters can be converted to utf-8 but the reverse is not true (for example, japanese glyphs cannot be converted to iso-8859-2).

I'd recommend reading Perl Programming/Unicode UTF-8. It's mostly about iso-8859-1 <-> UTF-8 in a CGI::Application/Apache stack but it's probably the best written article about encoding issues and I'm sure you can glean some relevant tips.

-derby
  • Comment on Re: Change encoding of a string from utf8 to iso-8859-2

Replies are listed 'Best First'.
Re^2: Change encoding of a string from utf8 to iso-8859-2
by bucz (Novice) on Mar 05, 2010 at 07:29 UTC
    well, I do just
    $ret = from_to($ret, "iso-8859-2", "utf8");
    no magic. I fetch webpage, cut sime content and want to display it. but this one does not work : /
      Apart from the fact that you haven't provided sample data or enough code to demonstrate what you mean by "does not work", you either didn't read or didn't understand what the Encode man page says about the "from_to()" function: from_to() returns the length of the converted string (in octets), after doing the conversion "in-place" (i.e. replacing the original content of a string variable with the converted content).

      This one line of code you showed us is assigning the return value (length in octets) to the same variable that you are trying to convert. That obliterates whatever string you just converted, replacing it with a number.

      ...no magic. I fetch webpage, cut sime content and want to display it. but this one does not work : /

      That is not adequate to replicate your problem. How (Not) To Ask A Question