user2567369
user2567369

Reputation:

Reading word as a utf-8 from database php

i have a database which in that word is with utf-8 encoded

enter image description here

i am reading database by below code

       <?php
       header("Content-Type: text/html;charset=UTF-8");
       include("./config.php");
       $sql=mysql_query("SET NAMES 'utf8'");
       $sql=mysql_query("SELECT * FROM  `Albanian` WHERE  (`COL 2`='".$_GET['q']."')");
       $rowCount = mysql_num_rows($sql);
       if($rowCount > 0)
       {
        while($row = mysql_fetch_array($sql))
         {
         echo utf8_encode($row['COL 3']);
          }
         }else
         {
        echo "No Word Found";
       }
      ?>

but if i search with word "a" the output is looking like below

+enter image description here

which is not something like proper with UTF-8 can anybody help me how to resolve this issue

Upvotes: 2

Views: 127

Answers (3)

Ma&#39;moon Al-Akash
Ma&#39;moon Al-Akash

Reputation: 5423

Your data is already in utf-8 format, no need to call utf8_encode

Upvotes: 1

flcoder
flcoder

Reputation: 710

Browsers are finicky. Try it with proper HTML 5 doc output. See "Minimum HTML 5 Document" from http://www.w3schools.com/html/html5_intro.asp

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Title of the document</title>
    </head>

    <body>
        Content of the document......
    </body>
</html>

Also, I don't remember where I got this from, but I use an .htaccess file for every php project I do and I always stick to UTF-8 for every project if I have control.

# MAKE SURE WE GET ERROR REPORTING

php_flag display_startup_errors on
php_flag display_errors         on
php_flag html_errors            on

# USE UTF-8
php_value mbstring.language             neutral
php_value mbstring.internal_encoding    utf-8
php_value mbstring.encoding_translation on
php_value mbstring.http_input           auto
php_value mbstring.http_output          utf-8
php_value mbstring.detect_order         auto
php_value mbstring.substitute_character none
php_value default_charset               utf-8

Upvotes: 0

Zahidul Hossein Ripon
Zahidul Hossein Ripon

Reputation: 672

<meta http-equiv = "Content-Type" content = "application/xhtml+xml; charset=utf-8"/> 
<?php
       include("./config.php");
       $sql=mysql_query("SET NAMES 'utf8'");
       $sql=mysql_query("SELECT * FROM  `Albanian` WHERE  (`COL 2`='".$_GET['q']."')");
       $rowCount = mysql_num_rows($sql);
       if($rowCount > 0)
       {
        while($row = mysql_fetch_array($sql))
         {
         echo $row['COL 3'];
         }
       }
       else
       {
        echo "No Word Found";
       }
?>

Upvotes: 0

Related Questions