views:

57

answers:

2

I have a script which produces text output. That script grabs content from a MySQL database encoded as latin1_general_ci. Including that script in a HTML page marked as iso-8859-1 works fine.

How do I capture the output of this script and include it in a HTML page encoded in utf-8?

I have attempted to capture the output of the script using ob_start() and then spit it out with ob_end_flush(). The idea was to convert the charset of the output from ob_end_flush().

I've tried the following, but the content in iso-8859-1 doesn't seem to be converting (I still see funny characters in my browser):

utf8_encode(ob_end_flush());
+1  A: 

ob_end_flush sends the data to the client and returns a boolean. You should use ob_get_flush.

http://ar2.php.net/ob_get_flush

Johnco
+1  A: 

To do the converion, you can also execute this query SET NAMES utf8 after opening the connection with the DB. It will instruct MySQL to do the latin-1 to UTF-8 conversion and you won't need the utf8_encode anymore.

gimpe
I can't force this in my script as it's used elsewhere, but thanks for the tip.
eoinoc