F
Francesco Moi
Hello.
I'm parsing an XML file, and storing some of the contents into
a MySQL database. I use Perl (XML:arser).
I was adviced that 'XML:arser' works with UTF-8 charset, so
I use 'Unicode::MapUTF8' to convert text.
But:
* If I parse the XML file, and print the text, I get 'música' (OK).
* If I parse the XML file, store the text, and print the
stored text, I get 'música' (wrong)
* If I parse the XML file, store the text, convert the stored text
from UTF-8 to ISO-8859-1 charset, and print it, I get 'música' (OK).
* If I parse the XML file, convert the text from UTF-8 to ISO-8859-1
charset, store it, and print the stored (and converted) text,
I get 'música' (wrong, but I did not expect it).
I only want to store text into my database and print it correctly,
but converting it _BEFORE_ storing. I don't feel like converting
each text I read from the database.
The piece of code I use to convert text is:
--------//----------
use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
sub convert_unicode
{
$my_text = $_[0];
my $converted = from_utf8({ -string => $my_text, -charset => 'ISO-8859-1' });
return $converted;
}
--------//---------
Does anybody know what I am doing wrong? Thank you very much.
I'm parsing an XML file, and storing some of the contents into
a MySQL database. I use Perl (XML:arser).
I was adviced that 'XML:arser' works with UTF-8 charset, so
I use 'Unicode::MapUTF8' to convert text.
But:
* If I parse the XML file, and print the text, I get 'música' (OK).
* If I parse the XML file, store the text, and print the
stored text, I get 'música' (wrong)
* If I parse the XML file, store the text, convert the stored text
from UTF-8 to ISO-8859-1 charset, and print it, I get 'música' (OK).
* If I parse the XML file, convert the text from UTF-8 to ISO-8859-1
charset, store it, and print the stored (and converted) text,
I get 'música' (wrong, but I did not expect it).
I only want to store text into my database and print it correctly,
but converting it _BEFORE_ storing. I don't feel like converting
each text I read from the database.
The piece of code I use to convert text is:
--------//----------
use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
sub convert_unicode
{
$my_text = $_[0];
my $converted = from_utf8({ -string => $my_text, -charset => 'ISO-8859-1' });
return $converted;
}
--------//---------
Does anybody know what I am doing wrong? Thank you very much.