i hav a database that contains spanish characters. to populate the database i am getting the values from client page which has character encoding=UTF-8. when i insert the va
Change your mysql database/ table / column encoding to UTF-8 (and also set the collation to a compatible value).
ALTER TABLE mytable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE mytable
MODIFY country CHAR(50)
CHARACTER SET utf8 COLLATE utf8_general_ci;
Also specify the char set at the PHP side when connecting.
mysql_set_charset('utf8',$conn);
Take a look at this article for further info and a script to batch change every table / column in a database.
Check two things first:
I just wasted 4 hours on the same problem as you.
Everything is in UTF-8
EG:
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
The MySQL database is in UTF-8 PHP is in UTF-8
After four hours and on many occasions tearing my hair out I have found a solution that works.
$content = htmlentities($row[mystring], ENT_QUOTES, "ISO-8859-1");
$content = html_entity_decode($content);
It takes the accents converts them to html characters then converts them back into UTF-8
This is a great hack and it works perfectly.
For some inexplicable reason, the data in my MYSQL database is not in the UTF-8 format even though I have gone to extreme measures like exporting the data to a text file in phpmyadmin saving it as UTF-8 in a text editor and re-importing it. None of this worked.