Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #2191

Re: Displaying UTF-8-encoded strings from MySQL with PHP

From "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid>
Newsgroups comp.lang.php
Subject Re: Displaying UTF-8-encoded strings from MySQL with PHP
Date 2011-06-15 16:17 +0200
Organization http://alvaro.es/
Message-ID <itaeu4$lgp$1@dont-email.me> (permalink)
References (1 earlier) <ita1dk$1b8$1@dont-email.me> <0477a430-ce92-409c-8096-f3ec2108bc54@x3g2000yqj.googlegroups.com> <673fc65f-1d71-40d2-92ac-354b29536662@r2g2000vbj.googlegroups.com> <ae9a8953-fc02-4da2-b720-1a3886e5e1e8@a10g2000vbz.googlegroups.com> <5eb8ed99-fa58-4112-bdcc-93035b34b588@z37g2000yqb.googlegroups.com>

Show all headers | View raw


El 15/06/2011 15:50, Luke escribió/wrote:
>>>> // Simply performs a query and returns mysql_fetch_assoc on the first
>>>> result
>>>> $hex = $theDB->getResult("SELECT HEX(link_text) FROM language WHERE
>>>> id=2");
>>
>>>> // Echos "C3BC" (which is the correct value for the character in the
>>>> DB ("ü"))
>>>> echo $hex['HEX(link_text)'];
>>
>>>> // Selecting the actual value instead of its hex-represenation
>>>> $char = $theDB->getResult("SELECT link_text FROM language WHERE
>>>> id=2");
>>
>>>> // Echos "fc" (which is " " (broken character))
>>>> echo bin2hex($char['link_text']);
>>
>>>> I'm a little confused. I tried various functions on this:
>>
>>>> $theDB->query("SET NAMES ‘utf8′");
>>>> mysql_set_charset('utf8');
>>>> mb_internal_encoding("UTF-8");
>>
>>>> mb_internal_encoding("UTF-8");
>>
>>>> Nothing helps. Changing configurations is not impossible, but very
>>>> difficult. Also the database seems fine, as HEX(xx) returns the
>>>> correct value, and in my PHP-Scripts I can use UTF-8 characters (that
>>>> aren't loaded from the database) and they work too. There must be
>>>> something in 'between'…
>>
>>> And it seems FC is the "Hex code point" of the character I'm looking
>>> for. But I actually have no clue what to do. Wikipedia says Hex code
>>> point marks the range in which characters are assigned to languages
>>> (more or less), but i'm not sure why that is returned or even how to
>>> handle this.
>>
>> Oh wait FC is the ASCII-Value for ü. So the question is, why does PHP
>> recieve an ASCII-char if the MySQL-Function HEX() returns the correct
>> UTF-8 hexvalue?


ASCII is a 7-bit encoding that does not have non-English letters like 
"ü". That FC you get is the ISO-8859-1 code. The data gets converted 
from UTF-8 to ISO-8859-1 (or a similar charset).

> Ok, I got it. As supposed here http://akrabat.com/php/utf8-php-and-mysql/
> I had to query "SET NAMES UTF8;" right after I connected to the
> database. No need to change tables or configuring Apache and PHP

Hadn't you tried that already?

http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

 > (well, I had to insert meta-tags setting UTF-8 as charset, but apart
 > from that there was nothing else to do).

Meta-tags are not useful unless you save the page to disk from your 
browser and open it later. You should either use header() to set the 
Content-Type header or configure it via .htaccess.


-- 
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Displaying UTF-8-encoded strings from MySQL with PHP Luke <kickingjesus@gmail.com> - 2011-06-15 03:18 -0700
  Re: Displaying UTF-8-encoded strings from MySQL with PHP "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-06-15 12:26 +0200
    Re: Displaying UTF-8-encoded strings from MySQL with PHP Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-15 06:53 -0400
      Re: Displaying UTF-8-encoded strings from MySQL with PHP "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-06-15 13:57 +0200
        Re: Displaying UTF-8-encoded strings from MySQL with PHP Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-15 12:07 -0400
          Re: Displaying UTF-8-encoded strings from MySQL with PHP "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-06-16 09:29 +0200
    Re: Displaying UTF-8-encoded strings from MySQL with PHP Luke <kickingjesus@gmail.com> - 2011-06-15 05:56 -0700
      Re: Displaying UTF-8-encoded strings from MySQL with PHP Luke <kickingjesus@gmail.com> - 2011-06-15 06:05 -0700
        Re: Displaying UTF-8-encoded strings from MySQL with PHP Luke <kickingjesus@gmail.com> - 2011-06-15 06:23 -0700
          Re: Displaying UTF-8-encoded strings from MySQL with PHP Luke <kickingjesus@gmail.com> - 2011-06-15 06:50 -0700
            Re: Displaying UTF-8-encoded strings from MySQL with PHP "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-06-15 16:17 +0200
              Re: Displaying UTF-8-encoded strings from MySQL with PHP Tim Streater <timstreater@waitrose.com> - 2011-06-15 15:26 +0100
  Re: Displaying UTF-8-encoded strings from MySQL with PHP Jo Schulze <antispam@feuersee.de> - 2011-06-16 23:34 +0200
    Re: Displaying UTF-8-encoded strings from MySQL with PHP "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-06-17 13:23 +0200

csiph-web