April 29, 2012

PHP UTF-8 Encoding in HTML Input Box

Question by Wasim

Here what is in database

Seilpendel für Tragsysteme

now i am loading it into textbox via AJAX but what loads into textbox is

Seilpendel f�r Tragsysteme

but i want correct string Seilpendel für Tragsysteme into inputbox

i have tried

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

but not its working

Answer by mcdado

Make sure the db is encoded in UTF8, or use utf8_encode() or utf8_decode() when loading data from db or when writing back.

Answer by Starx

The correct way solving this problem is to configure database to use UTF8 as their character encoding in and out.

RUN The following query after connecting to the database, one time and everything should start working.

SET NAMES 'utf8';

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!