Hi All! I have problem with reading persian text from MySQL 5.0.51a on my webpage (php). I have got this problem when change my webhotel and have got MySQL 5.0.51a insted of my MySQL 4... The persian text I am getting is only like "????????? ??????". but it is working with english text and swesish text. here is my php/html code: <html> <head> <META name="description" content="Education Center for Afghan children. Learn Language Dari and Pashto, educational software and books in Dari/ Farsi /Persian and Pashto. Forum for kids and more"> <META name="keywords" content="Dari, Pashto, Farsi, Parsi, Persian, Afghan, Afghanistan, language, software, books, book, educational material, language course, Dari, Dari language, Persian, Fari, text Chat"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>مرکز آموزش برای کودکان و نوجوانان افغان </title> </head> <body> <script LANGUAGE="JavaScript"> document.oncontextmenu=function(){return false} if(document.layers){window.captureEvents(Event.MOUSEDOWN);window.onmousedown=function(e){if(e.target==document)return false}} else{document.onmousedown=function(){return false}} function disableselect(e){return false} function reEnable(){return true} document.onselectstart=new Function("return false") if(window.sidebar){document.onmousedown=disableselect document.onclick=reEnable} </script> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; vertical-align: text-top; word-spacing: 0; text-indent: 0; text-align: left; line-height: 100%; border-width: 0; margin: 0" bordercolor="#111111" width="974" height="1544"> <tr> <td width="100%" style="border-style: none; border-width: medium"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%"> <tr> <td width="974" style="border-style: none; border-width: medium" height="64" valign="top"> <?php include('FDate.php'); include("h_dari.php"); ?> <p align="center" style="margin-top: 0; margin-bottom: 0"> <font color="#FF0000" size="2">امروز <b> <?=jdate("l d F Y")?> </b> ه.ش مطابق <?=date("d-m-Y")?> ميلادي ساعت <?=jdate("G:i")?> </b> </font> </td> </tr> <tr> <td width="974" style="border-style: none; border-width: medium" height="1440" valign="top"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%"> <tr> <td width="185" style="border-style: none; border-width: medium" height="1440"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%" height="31"> <tr> <td width="185" style="border-style: none; border-width: medium" height="747" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> <?php include("GameListD.php"); ?> </td> </tr> <tr> <td width="185%" style="border-style: none; border-width: medium" height="705" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> </td> </tr> </table> </td> <td width="224" style="border-style: none; border-width: medium" height="1440" valign="top"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-left-width: 0; border-right-width: 0; border-bottom-width: 0" bordercolor="#111111" width="100%" height="1442"> <tr> <td width="224" style="border-style: solid; border-width: 1" height="15" background="picture/titleS_yello.gif" dir="rtl"> <p style="margin-top:0; margin-bottom:0" dir="rtl" align="center"><span lang="fa"> <font color="#0000FF"><b>خبر جديد</b></font></span></td> </tr> <tr> <td width="224" style="border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-bottom-style: none; border-bottom-width: medium" height="1349" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> <?php include("NewsD.php"); ?> </p> <p style="margin-top: 0; margin-bottom: 0"> <i><font size="1"> <? echo $Datum ?> </font></i> </p> <p style="margin-top: 0; margin-bottom: 0" align="center"> <b> <font color="#0000FF"> <? echo $Rubrik ?> </font> </b> </p> <p style="margin-top: 0; margin-bottom: 0" align="center"> <font size="2" color="#CCCC00"> <? echo $Meddelande ?> </font> </p> <p style="margin-top: 0; margin-bottom: 0" align="center"> <? echo "----------" ?> </p> <p style="margin-top:0; margin-bottom:0"> </td> </tr> </table> </td> <td width="360" style="border-style: none; border-width: medium" height="1440"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%"> <tr> <td width="360" style="border-style: none; border-width: medium" height="800" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> <?php include("SoftwareListD.php"); ?> </td> </tr> <tr> <td width="360" style="border-style: none; border-width: medium" height="600" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> </td> </tr> </table> </td> <td width="205" style="border-style: none; border-width: medium" height="1440" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> <?php include("BookListD.php"); ?> </td> </tr> </table> </td> </tr> <tr> <td width="974" style="border-style: none; border-width: medium" height="40" valign="top"> <p align="center" dir="rtl" style="margin-top: 0; margin-bottom: 0"><font size="1">© </font><span lang="fa"> <font face="Tahoma" size="1">تمام امتيازات و طراحى اين سايت محفوظ به مرکز آموزش برای کودکان و نوجوانان افغان ميباشد.</font></span></td> </tr> </table> </td> </tr> </table> </body> </html> Code (markup):
When you create the table in mysql, be sure to specify the character set. Example CREATE TABLE testTable ( fldOne VARCHAR(255); fldTwo VARCHAR(255); ) CHARACTER SET utf8 COLLATE utf8_general_ci; Code (markup): Do this after each table creation statement. The COLLATE keyword is used to specify how handle the data during sorting. After you connect to the database through PHP, the first query you send needs to be "SET NAMES 'utf8'".
Hi! Thanks for helping! Unfortunately it does not work with this new table. It display only “??????â€. //Sofi
Is there anyone can help me? I can see persian (utf-8) character but when I use the following code to get the text from MySQL to php, then I am only getting "????????". NewsD.php: <?php header('Content-Type: text/html; charset=UTF-8'); include 'config.php'; include 'opendb.php'; $query = "SELECT * FROM NewsD"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { //echo "<br />".$row['Datum']."<br />".$row['Rubrik']."<br />".$row['Meddelande']."<br />". " ----------- "."<br />"; $Datum=$row['Datum']; $Rubrik=$row['Rubrik']; $Meddelande=$row['Meddelande']; } include 'closedb.php'; ?> Code (markup): I have only include the NewsD.php in index here: <? header('Content-Type: text/html; charset=UTF-8'); ?> <html> <head> <META name="description" content="Education Center for children"> <META name="keywords" content="Persian, Afghan, Afghanistan"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> Persian</title> </head> <script LANGUAGE="JavaScript"> document.oncontextmenu=function(){return false} if(document.layers){window.captureEvents(Event.MOUSEDOWN);window.onmousedown=function(e){if(e.target==document)return false}} else{document.onmousedown=function(){return false}} function disableselect(e){return false} function reEnable(){return true} document.onselectstart=new Function("return false") if(window.sidebar){document.onmousedown=disableselect document.onclick=reEnable} </script> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; vertical-align: text-top; word-spacing: 0; text-indent: 0; text-align: left; line-height: 100%; border-width: 0; margin: 0" bordercolor="#111111" width="974" height="1544"> <tr> <td width="100%" style="border-style: none; border-width: medium"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%"> <tr> <td width="974" style="border-style: none; border-width: medium" height="64" valign="top"> <?php include('FDate.php'); include("h_dari.php"); ?> <p align="center" style="margin-top: 0; margin-bottom: 0"> <font color="#FF0000" size="2">امروز <b> <?=jdate("l d F Y")?> </b> Ù‡.Ø´ مطابق <?=date("d-m-Y")?> ميلادي ساعت <?=jdate("G:i")?> </b> </font> </td> </tr> <tr> <td width="974" style="border-style: none; border-width: medium" height="1440" valign="top"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%"> <tr> <td width="185" style="border-style: none; border-width: medium" height="1440"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%" height="31"> <tr> <td width="185" style="border-style: none; border-width: medium" height="747" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> <?php include("GameListD.php"); ?> </td> </tr> <tr> <td width="185%" style="border-style: none; border-width: medium" height="705" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> </td> </tr> </table> </td> <td width="224" style="border-style: none; border-width: medium" height="1440" valign="top"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-left-width: 0; border-right-width: 0; border-bottom-width: 0" bordercolor="#111111" width="100%" height="1442"> <tr> <td width="224" style="border-style: solid; border-width: 1" height="15" background="picture/titleS_yello.gif" dir="rtl"> <p style="margin-top:0; margin-bottom:0" dir="rtl" align="center"><span lang="fa"> <font color="#0000FF"><b>خبر جديد</b></font></span></td> </tr> <tr> <td width="224" style="border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-bottom-style: none; border-bottom-width: medium" height="1349" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> [COLOR="red"][B]<?php include("NewsD.php"); ?>[/B] [/COLOR] </p> <p style="margin-top: 0; margin-bottom: 0"> <i><font size="1"> <? echo $Datum ?> </font></i> </p> <p style="margin-top: 0; margin-bottom: 0" align="center"> <b> <font color="#0000FF"> [COLOR="red"][B]<? echo $Rubrik ?> [/B][/COLOR] </font> </b> </p> <p style="margin-top: 0; margin-bottom: 0" align="center"> <font size="2" color="#CCCC00"> [COLOR="red"][B] <? echo $Meddelande ?> [/B][/COLOR] </font> </p> <p style="margin-top: 0; margin-bottom: 0" align="center"> <? echo "----------" ?> </p> <p style="margin-top:0; margin-bottom:0"> </td> </tr> </table> </td> <td width="360" style="border-style: none; border-width: medium" height="1440"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%"> <tr> <td width="360" style="border-style: none; border-width: medium" height="800" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> <?php include("SoftwareListD.php"); ?> </td> </tr> <tr> <td width="360" style="border-style: none; border-width: medium" height="600" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> </td> </tr> </table> </td> <td width="205" style="border-style: none; border-width: medium" height="1440" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> <?php include("BookListD.php"); ?> </td> </tr> </table> </td> </tr> <tr> <td width="974" style="border-style: none; border-width: medium" height="40" valign="top"> <p align="center" dir="rtl" style="margin-top: 0; margin-bottom: 0"><font size="1">© </font><span lang="fa"> <font face="Tahoma" size="1">تمام امتيازات Ùˆ طراØÙ‰ اين سايت Ù…ØÙوظ به مرکز آموزش برای کودکان Ùˆ نوجوانان Ø§ÙØºØ§Ù† ميباشد.</font></span></td> </tr> </table> </td> </tr> </table> </body> </html> Code (markup): Note: The same code has worked with the MySQL 4 with my before webhotel, when I change webhotel I have got MySQL 5. Now it does not working. //Sofi
Does utf-8 text display on anywhere the page? Or is it only the output from the database that isn't coming up properly?
It is only the output from the database that isn't coming up properly, I can see Persian text on my php-page which is not comming from database. //Sofi
Check out this website http://www.nicknettleton.com/zine/php/php-utf-8-cheatsheet That's the best resource I've been able to find for getting php working well with utf-8. Hopefully one of those things will help.
perhaps someone here is Persian and can help me translate this message? forums.digitalpoint.com/showthread.php?t=1640134 I would really appreciate it and it is also a good opportunity to test your translator
I think the best way is to post your requirements on any persian forum. That would help you sort your issue.
hello, were you ever able to solve this problem? I'm having the same issue now. I'm inserting into a mysql table using phpmyadmin, and the text inserts and shows up fine there without an issue, but when I query it from a webpage, all I get is ????
I managed to solve this problem. A previous suggestion in the forum solved it for me, which was to run the query "SET NAMES 'utf8'" before anything else.