0

in php I'm getting data from an utf8_unicode_ci database and storing the same into utf8_general_ci db. That seems to be not possible when the text contains em dashes.

Does anyone know if there is a way in php to convert the data from utf8_unicode to utf8_general?

Thanks a lot.

Katie
  • 609
  • 1
  • 6
  • 17

2 Answers2

1

Both utf8_general_ci instead of utf8_normal_ci are collations of the same character encoding/set (i.e. UTF-8). An a collation does define the order and equivalence of characters:

A difference between the collations is that this is true for utf8_general_ci:

ß = s

Whereas this is true for utf8_unicode_ci, which supports the German DIN-1 ordering (also known as dictionary order):

ß = ss

See Unicode Character Sets for more information.

So this shouldn’t have only affect operations where you compare characters/strings. Any other operation is unaffected.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
0

run

$charset = mysql_client_encoding($link);

echo "The current character set is: $charset\n";

to check the current encoding.

and also set the character set using

Here's an improved version of Janez R.'s function:

<?php
if (function_exists('mysql_set_charset') === false) {
    /**
     * Sets the client character set.
     *
     * Note: This function requires MySQL 5.0.7 or later.
     *
     * @see http://www.php.net/mysql-set-charset
     * @param string $charset A valid character set name
     * @param resource $link_identifier The MySQL connection
     * @return TRUE on success or FALSE on failure
     */
    function mysql_set_charset($charset, $link_identifier = null)
    {
        if ($link_identifier == null) {
            return mysql_query('SET CHARACTER SET "'.$charset.'"');
        } else {
            return mysql_query('SET CHARACTER SET "'.$charset.'"', $link_identifier);
        }
    }
}

and for utf-8

mysql_query("SET NAMES utf8", $conn);
Khurram Ijaz
  • 1,844
  • 5
  • 24
  • 43
  • You shouldn’t do that manually. See [my answer to “Is mysql_real_escape_string() broken?”](http://stackoverflow.com/questions/5288953/is-mysql-real-escape-string-broken/5289141#5289141). – Gumbo Jun 03 '11 at 15:31