1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Cannot get out utf-8 (persian) text from MySQL

Discussion in 'PHP' started by sofi420, Feb 1, 2009.

  1. #1
    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>&#1605;&#1585;&#1705;&#1586; &#1570;&#1605;&#1608;&#1586;&#1588; &#1576;&#1585;&#1575;&#1740; &#1705;&#1608;&#1583;&#1705;&#1575;&#1606; &#1608; &#1606;&#1608;&#1580;&#1608;&#1575;&#1606;&#1575;&#1606; &#1575;&#1601;&#1594;&#1575;&#1606; </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">&#1575;&#1605;&#1585;&#1608;&#1586; <b> <?=jdate("l  d  F Y")?>&nbsp;</b> &#1607;.&#1588;&nbsp; &#1605;&#1591;&#1575;&#1576;&#1602; 
    <?=date("d-m-Y")?>&nbsp; &#1605;&#1610;&#1604;&#1575;&#1583;&#1610; &nbsp;&nbsp;&#1587;&#1575;&#1593;&#1578;
     <?=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">&nbsp;</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>&#1582;&#1576;&#1585; &#1580;&#1583;&#1610;&#1583;</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">&nbsp;</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">&#1578;&#1605;&#1575;&#1605; &#1575;&#1605;&#1578;&#1610;&#1575;&#1586;&#1575;&#1578; &#1608; &#1591;&#1585;&#1575;&#1581;&#1609; &#1575;&#1610;&#1606; &#1587;&#1575;&#1610;&#1578; &#1605;&#1581;&#1601;&#1608;&#1592; &#1576;&#1607; 
            &#1605;&#1585;&#1705;&#1586; &#1570;&#1605;&#1608;&#1586;&#1588; &#1576;&#1585;&#1575;&#1740; &#1705;&#1608;&#1583;&#1705;&#1575;&#1606; 
            &#1608; &#1606;&#1608;&#1580;&#1608;&#1575;&#1606;&#1575;&#1606; &#1575;&#1601;&#1594;&#1575;&#1606; &#1605;&#1610;&#1576;&#1575;&#1588;&#1583;.</font></span></td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
    
    </body>
    
    </html>
    Code (markup):
     
    sofi420, Feb 1, 2009 IP
  2. w0tan

    w0tan Peon

    Messages:
    77
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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'".
     
    w0tan, Feb 2, 2009 IP
  3. sofi420

    sofi420 Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi!
    Thanks for helping!
    Unfortunately it does not work with this new table. It display only “??????”.


    //Sofi
     
    sofi420, Feb 3, 2009 IP
  4. sofi420

    sofi420 Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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")?>&nbsp;</b> ه.ش&nbsp; مطابق 
    <?=date("d-m-Y")?>&nbsp; ميلادي &nbsp;&nbsp;ساعت
     <?=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">&nbsp;</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">&nbsp;</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:confused:
     
    sofi420, Feb 5, 2009 IP
  5. linkstraffic

    linkstraffic Well-Known Member

    Messages:
    388
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    133
    #5
    have you saved your php file in utf-8 ?
     
    linkstraffic, Feb 5, 2009 IP
  6. sofi420

    sofi420 Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes, does not help!
     
    sofi420, Feb 5, 2009 IP
  7. w0tan

    w0tan Peon

    Messages:
    77
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Does utf-8 text display on anywhere the page? Or is it only the output from the database that isn't coming up properly?
     
    w0tan, Feb 5, 2009 IP
  8. sofi420

    sofi420 Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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:confused:
     
    sofi420, Feb 5, 2009 IP
  9. w0tan

    w0tan Peon

    Messages:
    77
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    w0tan, Feb 5, 2009 IP
  10. mims

    mims Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    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 :)
     
    mims, Jan 5, 2010 IP
  11. ptduran

    ptduran Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I think the best way is to post your requirements on any persian forum. That would help you sort your issue.
     
    ptduran, Jan 27, 2010 IP
  12. jfoo1984

    jfoo1984 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    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 ????
     
    jfoo1984, Nov 21, 2010 IP
  13. jfoo1984

    jfoo1984 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    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.
     
    jfoo1984, Nov 21, 2010 IP