Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by bucz (Novice)
on Mar 04, 2010 at 08:00 UTC ( [id://826644]=perlquestion: print w/replies, xml ) Need Help??

bucz has asked for the wisdom of the Perl Monks concerning the following question:

Great monks! I have a following problem: I fetch some websites, get some information and display it. Some of those pages are in iso-8859-2 , some in utf8. I want to convert them all into iso-8859-2 or utf8, so I can display them properly in the same html document. Question: hos to change pages' encoding? I tried to use use Encoding but I did not manage to apply it well :/
  • Comment on Change encoding of a string from utf8 to iso-8859-2

Replies are listed 'Best First'.
Re: Change encoding of a string from utf8 to iso-8859-2
by almut (Canon) on Mar 04, 2010 at 08:22 UTC

    The first step to solving the issue would be to compose a self-contained snippet of code which shows how you've tried to use Encode (which I suppose you're referring to). Then post it here. That way we won't have to guess what you might have done wrong...

Re: Change encoding of a string from utf8 to iso-8859-2
by derby (Abbot) on Mar 04, 2010 at 12:14 UTC

    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
      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

Re: Change encoding of a string from utf8 to iso-8859-2
by Anonymous Monk on Mar 04, 2010 at 08:22 UTC
    Question: hos to change pages' encoding? I tried to use use Encoding but I did not manage to apply it well :/

    Show code :)

Re: Change encoding of a string from utf8 to iso-8859-2
by wazoox (Prior) on Mar 05, 2010 at 15:19 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://826644]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-23 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found