Page 1 of 1

Converting PHP to unicode (UTF-8) format

Posted: Mon Sep 11, 2006 9:34 pm
by Leao
Hi, I'm using the following PHP code to retrieve and print text from a mysql database. I have created a Flash movie that retrieves the text generated by this PHP file and displays it. For some reason some of the characters visible in the PHP file are invisible in the Flash movie, such as the characters '+' and '€'. I have spoken to a Flash expert about this and he suggested encoding my PHP file as unicode (UTF-8) format as Flash prefers this. Do you know how I can do this?

Thank you,

Leao

Code: Select all

<?php
mysql_connect("mysql.myurl.com","username","password") or die(mysql_error());
mysql_select_db("username_database") or die(mysql_error()); 

$result = mysql_query("SELECT * FROM database")
or die(mysql_error());  

$row = mysql_fetch_array( $result );

echo $row['landline'];
?>

Posted: Mon Sep 11, 2006 9:41 pm
by Ambush Commander
This really has nothing to do with the encoding of your PHP file. We need to know a few things:

1. What version of MySQL are you using?
2. If you are using 4.1 , what encoding is your table set at?

At least you'll need to convert the data in the database to UTF-8 on loading (probably from ISO 8895-1), but ideally the data gets stored in the database as UTF-8 to begin with.

Posted: Tue Sep 12, 2006 1:29 am
by dibyendrah
You may alter the table character-set to utf8 if you are using MySQL 4.1 or higher. Also, you may need to execute the following query to let your MySQL server know what character-set you want to use.

Try

Code: Select all

<?php
header('Content-Type: text/plain; charset=utf-8');
$connection = mysql_connect("mysql.myurl.com","username","password") or die(mysql_error());
mysql_query('SET NAMES utf8', $connection);
mysql_select_db("username_database", $connection) or die(mysql_error());

$result = mysql_query("SELECT * FROM database")
or die(mysql_error()); 

$row = mysql_fetch_array( $result );

echo $row['landline'];
?>
Hope this will solve your problem.

Cheers,
Dibyendra

Posted: Thu Sep 14, 2006 7:33 am
by Leao
Thanks. I'm using MySQL version 4.0.27. How do I find out in PHP myAdmin what encoding my table is set to?

Thanks again,

leo

Posted: Thu Sep 14, 2006 7:38 am
by Weirdan
for 4.0.x encoding is set on a per-server basis