March 9, 2012

Textarea not showing hebrew text from mysql

Question by Prateek

I’m trying to return some particular text from mysql into a textarea. Now this text returning from mysql has

    collation=utf8_unicode_ci 

and the charset is set by adding this line in my php file.

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

Cant figure out the problem here. Everything looks alright but why is the textarea not showing hebrew text? Instead it shows “???????” – Question marks.

Thanks.

Answer by Starx

During the data entry, or retrieval, the MySQL must be configured to accept unicode(UTF-8) data. There are number of ways, you can do this

  1. Place this line on the database connection part

    mysql_set_charset('utf8',$link); //$link is your connection identifier
    
  2. Run charset utf8 on CLI

  3. Use SET NAMES 'utf8' as your first query to the database

Moreover, while outputting such data the screen, the html should be configured to understand unicode characters as well. Use

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

At the top of the displaying page.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!