For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > February 2005 > How to convert latin1 to utf8









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to convert latin1 to utf8
francescomoi@europe.com

2005-02-25, 3:59 pm

Hi.

I've got some texts in Latin1 and like to convert to UTF-8.

Is this possible with 'Unicode::String'???

Thank you very much.

Robert Sedlacek

2005-02-25, 3:59 pm

francescomoi wrote:

> Is this possible with 'Unicode::String'???


The Docs seem so, but I think I would C<use Encode;>.

--
http://www.dunkelheit.at/
...and in darkness bind them.

Villy Kruse

2005-02-28, 8:57 am

On 25 Feb 2005 07:53:47 -0800,
francescomoi@europe.com <francescomoi@europe.com> wrote:


> Hi.
>
> I've got some texts in Latin1 and like to convert to UTF-8.
>
> Is this possible with 'Unicode::String'???
>


In combination with Unicode::Map it works on version 5.005

use Unicode::Map();
use Unicode::String qw(utf8 utf16);
my $CHARSET = 'ISO-8859-1';
my $Map = new Unicode::Map($CHARSET);
sub latin_to_utf8 { utf16($Map->to16($_[0]))->utf8; }
sub utf8_to_latin { $Map->to8(utf8($_[0])->utf16); }


Villy
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com