22
table 'abc' data :

tid    title

  1      வெள்ளிக்கிழமை ஐ.

  2      கோலாகல தொடக்க 


$sql=mysql_query("select title from abd where tid='1'");

$row=mysql_fetch_array($sql);

$title = $row['title'];

echo $title;

OutPut displaying like this:

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

But I want to display

வெள்ளிக்கிழமை ஐ.

Solution

<?php
    mysql_query ("set character_set_results='utf8'");   

    $sql=mysql_query("select title from abd where tid='1'");

    $row=mysql_fetch_array($sql);

    $title = $row['title'];

    echo $title;

?>
3
  • Beautiful characters! Especially ஐ. Commented Mar 15, 2010 at 20:04
  • If this is PHP code, do not use the old mysql_* API; switch to the newer (and safer) mysqli_* or PDO. Commented Jun 27, 2019 at 22:41
  • See "question mark" in stackoverflow.com/questions/38363566/… Commented Jun 27, 2019 at 22:43

7 Answers 7

37

Try to set charachter encoding after mysql_connect function like this:

 mysql_query ("set character_set_client='utf8'"); 
 mysql_query ("set character_set_results='utf8'"); 

 mysql_query ("set collation_connection='utf8_general_ci'"); 
Sign up to request clarification or add additional context in comments.

3 Comments

@JeffDavis They are different and you need to use all 3
@KasunSiyambalapitiya try this: mysqli_set_charset($link, 'utf8');
If you are going to update a field using that getting from a select statement, execute the above configurations after select query execution.
10

For new version of PHP which used mysqli, use this code after connect to mysql:

mysqli_set_charset($link, 'utf8');

1 Comment

You are my hero bro!
7

Try to make sure the browser recognizes the page as Unicode.

Generally, this can be done by having your server send the right Content-type HTTP header, that includes the charset you're using.


For instance, something like this should work :

header('Content-type: text/html; charset=UTF-8');
echo "வெள்ளிக்கிழமை ஐ";


If this works, and your dynamically generated page still doesn't :

  • make sure your data in your MySQL database is in UTF-8 too
    • this can be set for each table, or even columns, in MySQL
  • and make sure you are connecting to it using UTF-8.

Basically, all your application should use the same encoding :

  • PHP files,
  • Database
  • HTTP server

1 Comment

I had to combine your answer and antyrat's answer to get it work
3

execute query

SET NAMES 'utf8'

right after connecting to database

Comments

0

First you need to convert your mysql data format to utf-8, see this great article by oreilly:

.

Turning MySQL data to UTF-8

.

After that make sure that your page's encoding type is utf-8:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

2 Comments

@Srinivas Tamada: The final answer you chose did the same thing what has been told in the oreily article i posted the link above. Anyways, it is good that you found the solution. Thanks..
Link is dead, which is why answers should not be links.
0
<?php header('Content-type: text/html; charset=UTF-8');echo "<font face='Bamini' size='5'>" . "m.Nkhfd; Fkhh;" ."<br />";
echo "<font face='Bamini' size='10'>" . "m.Nkhfd; Fkhh;" ."<br />";
?>

or

<?php
header('Content-type: text/html; charset=UTF-8');
echo "வெளà¯à®³à®¿à®•à¯à®•ிழமை à®";
?>

Comments

-1

While inserting the data into a MySQL database using the relevant collation (ex. utf8_general_ci for Unicode characters, i.e Hindi). Also in use the PHP predefined function utf8_decode to display the characters in HTML.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.