Re: Displaying UTF-8-encoded strings from MySQL with PHP [message #174533 is a reply to message #174508] |
Thu, 16 June 2011 21:34 |
Jo Schulze
Messages: 15 Registered: January 2011
Karma:
|
Junior Member |
|
|
Luke wrote:
> I'm trying to migrate my project from ISO-8859-1 (Western Europe) to
> UTF-8. I *can* write special characters as regular text in my php-
> files, I can use special characters in echo-statements and I can even
> use special characters in .ini-files, load them, and display them. But
> when I load Strings with special characters from MySQL and display
> them, the string's "broken".
Which MySQL Server version are we talking about?
> <?xml version="1.0" encoding="utf-8" ?>
> and
> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
Both instruct the client that the data to be displayed should be UTF-8.
No verification done.
> in the markup. In the database I tried to set my table's collation to
> "utf8_general_ci".
As the name implies, the collation does only affect the sorting behavior
of MySQL. It does _not_ change the encoding of the database content.
> Also I tried the following functions:
>
> mysql_query("SET NAMES ‘utf8′");
good one
> mysql_set_charset('utf8');
good one (if avail)
> mb_internal_encoding("UTF-8");
Depends on your application and mbstring usage, usually bad choice.
> all not at the very beginning of my script, but before I queried the
> database and before I printed the results. I still keep getting
> 'wierd' characters.
1) Dump your DB to SQL
2) Convert the content from the former encoding to UTF-8 (eg. iconv)
3) Change MySQL metadata
4) Import the UTF-8 dump
5) Change DB wrapper code to negotiate UTF-8 as encoding (This is the
point where a DB wrapper comes in handy, if you haven't noticed before).
|
|
|