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


Groups > comp.lang.php > #2196

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

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Displaying UTF-8-encoded strings from MySQL with PHP
Date 2011-06-15 12:07 -0400
Organization A noiseless patient Spider
Message-ID <italc3$4n8$1@dont-email.me> (permalink)
References <e1fa9d06-3720-4489-9667-14bba4aa3506@d1g2000yqm.googlegroups.com> <ita1dk$1b8$1@dont-email.me> <ita2uk$a3f$1@dont-email.me> <ita6mq$vtv$1@dont-email.me>

Show all headers | View raw


On 6/15/2011 7:57 AM, "Álvaro G. Vicario" wrote:
> El 15/06/2011 12:53, Jerry Stuckle escribió/wrote:
>>> http://www.itnewb.com/v/UTF-8-Enabled-Apache-MySQL-PHP-Markup-and-JavaScript
>>>
>>>
>>>
>>>
>>> Whatever, are you sure that your data is actually stored as valid UTF-8
>>> after the migration?
>>>
>>> The HEX() function can be handy:
>>>
>>> http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_hex
>>>
>>>
>>>
>>>
>>
>> Álvaro, I admit I'm not great at UTF-8. This is a great guide if you
>> have your own server and want everything in UTF-8. However, do you know
>> of a similar reference for those who use shared servers and/or don't
>> want everything to default to UTF-8?
>
> I suppose you refer to the MySQL section (the rest of the stuff is easy
> to customize). I believe you can safely ignore it: it's only a trick to
> use UTF-8 with misconfigured clients. All you have to do is, well,
> configure your client properly. From my experience, this is all you need
> in PHP:
>

That's part of it, but even the PHP and Apache configurations can be 
hard to duplicate in your code, and generally you need to do it in every 
file.

Of course, you can use .htaccess to configure such, if the web server 
allows.  But I'm not even sure if some of those Apache settings are 
valid in the .htaccess (haven't checked).  And of course .htaccess isn't 
available if you're running on IIS.

>
> // Good old MySQL extension
> mysql_set_charset('utf8', $conn)
>
>
> // PDO
> $pdo_options = array(
> PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
> );
> $conn = new PDO(..., $pdo_options);
>
>
> With mb_convert_encoding() you can retrieve and store UTF-8 data even if
> your app does not use it ;-)
>
>

How's mb_convert_encoding() working?  Is it correct in converting 
(assuming, of course, the character exists in the character set being 
converted to).

I'm asking this because I only dabbled a bit in utf-8 several years ago, 
and haven't touched it since (yea, we Americans think the whole world 
revolves around us :) ).  But I may soon be involved in a project which 
does use it.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

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