[PHP] Re: Greek Characters from MySQL to PHP to the Browser: ??????

2006-08-10 Thread Colin Guthrie

John Wells wrote:

Thanks to everybody's suggestions, problem solved.  Yes, the default
encoding for PHP's mysql client is latin1.  So a quick query of:

SET NAMES 'utf8'

*per connection* works it all out.

The articles and links were very helpful in alluminating some of the
other particulars of working with utf-8.  These will take a bit more
reading and studying...


Glad you got it sorted.

For me, I've had best success treating all tables as latin1, with the 
connection also using lating and just knowing that all the text is 
UTF8 encoded It certainly hasn't come back to bite me in the bum yet!


Col.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Greek Characters from MySQL to PHP to the Browser: ??????

2006-08-08 Thread Colin Guthrie

John Wells wrote:

Hi Everybody,

Despite all of my Googling and noodling, I can't seem to figure this
out, and am hoping someone might be able to point me in the right
direction.

Scenario:
- Running Apache 1.3 on OSX 10.4, PHP 5.1.4, MySQL 5.0.19
- Greek text is stored in a MySQL database, encoding set to UTF-8
- From within a db admin like CocoaMySQL, the greek text looks normal
- PHP queries the db table for the greek text
- no matter how I echo the text to screen (see below), it only
produces '?' marks

What I've tried:
- force utf-8 headers to be sent  --- header(Content-type:
text/html; charset=UTF-8);
- indicate utf-8 in the meta tag -- meta http-equiv=Content-Type
content=text/html; charset=utf-8 /
- simpley echo the string as is -- echo $greek_string;


The above should be correct!


- wrap output in htmlentities() -- echo htmlentities($greek_string,
ENT_NOQUOTES, 'UTF-8');
- wrap output in utf8_decode() -- echo utf8_decode($greek_string);


Neither of the above should be used.


- If I copy and paste greek characters from the db table into a string
in my PHP script, and output that, it works just FINE, without any
htmlentities() or other functions.

I'm at a loss.  What am I doing wrong?


That I don't know :)

I'm guessing that there may be some setting inbetween the PHP and mysql 
layer that is mangling things.


You may need to setup the character set used for the communication 
between mysql and PHP.


Have a look on this page, and the comments on it. Perhaps you need to do 
something like in comment 2??


http://uk2.php.net/manual/en/function.mysql-client-encoding.php


Col

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Greek Characters from MySQL to PHP to the Browser: ??????

2006-08-08 Thread Michael B Allen
On Tue, 08 Aug 2006 18:00:29 +0100
Colin Guthrie [EMAIL PROTECTED] wrote:

  - If I copy and paste greek characters from the db table into a string
  in my PHP script, and output that, it works just FINE, without any
  htmlentities() or other functions.
  
  I'm at a loss.  What am I doing wrong?
 
 That I don't know :)
 
 I'm guessing that there may be some setting inbetween the PHP and mysql 
 layer that is mangling things.

Or maybe MySQL needs to be running in the UTF-8 locale. Try mysqldump
to get some text in a file and make sure it's really UTF-8. There are
a number of ways to tell if something is UTF-8. One is to create an
ASCII string with one non-ascii character like 'hĂȘllo' in the db and
then hexdump some mysqldump output. You should see single bytes for the
ASCII characters and then two or more bytes for the non-ascii character.

In general I would say a conversion is taking place somewhere. To fix,
verify what encoding is being used by mysql, the mysql client, PHP,
Apache, and the browser. If any one of those does not clearly output
UTF-8 the chain is broken. Start with MySQL and work your way down.

Mike

BTW: htmlentities has nothing to do with character conversions.

-- 
Michael B Allen
PHP Active Directory SSO
http://www.ioplex.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php