Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP, MySQL and International language support

Status
Not open for further replies.

johnsmith180

Programmer
Oct 26, 2005
27
GB
Hi

Currently, I am testing how to create an Arabic website with PHP and MySQL 4.1

I have set the collation of the database , table and column to "cp1256_general_ci"

Now I have this PHP code:

<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("ArabicTest", $con);

$result = mysql_query("SELECT * FROM Arabic where BINARY t1='????'") or die(mysql_error());

while($row = mysql_fetch_array($result))
{
echo $row['t1'];
echo "<br />";
}
?>

However, I am getting following text: "????". Please advise me how I can display the arabic text on the web page.

(If I run "SELECT * FROM Arabic where t1='????' " in phpmyAdmin, I can get the arabic text.)

Kind regards
 
try sending a unicode header before outputting ANY content

Code:
header('Content-Type: text/html; charset=utf-8');

you could also/instead set the default charset in php.ini



 
Thanks jpadie

I have tried
header('Content-Type: text/html; charset=utf-8'); or
header('Content-Type: text/html; charset=cp1256');

However, I still have the same problem.

Actually, one of the table rows contains the following characters (see the charcters in Red marker:

Now when this data is displayed on the webpage, the Arabic characters are being displayed correctly.

But for table rows that contains the actual Arabic characters: ????, I get ????

So I am not sure how to solve this. Hope someone will have a solution.

regards
 
try adding this to the page in the <head> tags (as well as the header directive)

Code:
<meta http-equiv='Content-Type' content='text/html; charset=cp1256' >

are you getting the same behaviour in IE and Firefox?
 
The following does not have any effect:
<meta http-equiv='Content-Type' content='text/html; charset=cp1256' >

I am getting the same behaviour in IE and Firefox

Thanks
 
can you post the code you are using to retrieve the data from the database and display it?
 
I have found the solution.

I need to set the character set for the MySQL connection, otherwise, mysql will not return arabic characters. So use the following after database connection has been setup:

mysql_query("SET CHARACTER SET cp1256", $con);

regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top