Search code examples
phpdatabaseencodingarabic

fix encoding Arabic data from database


fix encoding Arabic data from database ?

    function postTitle()
            {
        $postdb = mysql_query("SELECT * FROM wtable");
        $post = mysql_fetch_assoc($postdb);
            echo mb_detect_encoding($post['posttitle'],"UTF-8,ISO-8859-1");
            }
echo postTitle();

datebase encode: utf8_general_ci

result:

????????? ?????????????? ????????? ????? ???????

Solution

  • Assuming that the script is encoded UTF8 too, be sure that the connection also uses UTF8: Use this:

    mysql_query('SET names UTF8');
    

    ....before the SELECT inside the function.