Hi Monks,
I've checked out a bunch of threads regarding encoding and decoding but none really described my problem.

A while ago I changed my webhoster and setup a new MySQL db there which uses UTF8. I exported the old db (which didn't use UTF8) and imported it to the new db.

So far the good. The problem now is that special characters (EG german ones like ä, ü, ö, ß, ...) haven't been converted properly.

So now I have a database full with funny looking sentences.

Example: Ein gelber dreif├â┬╝├â┼©iger Greif auf gr├â┬╝n-rotem Grund, der ein Gelds├â┬ñckchen und eine Spitzhacke h├â┬ñlt
This should be: Ein gelber dreifüßiger Greif auf grün-rotem Grund, der ein Geldsäckchen und eine Spitzhacke hält

What I thought:

Get text from db.
$text =~ s/├â┬ñ/ä/g;
Repeat for all special characters.
Save changed text in db.

Unfortunately this doesn't work.
I'm printing out the text to my screen and there is no change after the conversion.
My problem right now is not a conversion between different encodings because I already am using UTF8. I need to somehow substitute the characters. But I'm probably not using the right substitutions because Perl handles those special characters different internally.
My current code:
#!/usr/bin/perl -w use strict; use warnings; use Encode; use DBI; use feature 'unicode_strings'; binmode(STDOUT, ":utf8"); my $db = "..."; my $user = "..."; my $pw = '...'; my $host = "..."; my $options = {RaiseError => 1, AutoCommit => 1, mysql_enable_utf8 => +1}; my $dbh = DBI->connect("DBI:mysql:$db:$host", $user, "$pw", $options) +|| die "Could not connect to database!"; my $sql = 'select post_id, post_text from phpbb_posts where post_id = +24358'; my $sth = $dbh->prepare($sql); $sth->execute() or die "Error: $DBI::errstr"; my ($id, $text) = $sth->fetchrow_array; print "id: $id text: $text"; $text =~ s/├â┬ñ/ä/g; $text =~ s/├â┬Â/ö/g; $text =~ s/├â┼©/ß/g; $text =~ s/├â┬╝/ü/g; print "\nid: $id text: $text";
The code tag seems to be having problems displaying the special characters. But I guess you get the idea.

In reply to Convert special characters in UTF8 by Digioso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.