0

I have a PHP script which is used by an Ajax function to pass some input variables in a MySQL database. But a string like "Camping Dragoske, DN73C, Burluși" is stored in the MySQL database like "Camping Dragoske, DN73C, BurluÈ™i, România" and is captured by the ajax.php file like "Camping Dragoske, DN73C, Burlu\u0219i, Rom\u00e2nia".

My HTML charset encoding is UTF-8, and the MySQL table is set to utf8_general_ci and the field is set to utf8_unicode_ci.

dda
  • 6,030
  • 2
  • 25
  • 34
Tudor Ravoiu
  • 2,130
  • 8
  • 35
  • 56
  • I would try to do something like: http://stackoverflow.com/questions/3959626/replace-unicode-character?rq=1 – Ido Green Jul 22 '12 at 06:57
  • Are you using jQuery to make the Ajax call? Otherwise you might need to convert from the charset Javascript uses internally to UTF-8 yourself. – Wolfgang Stengel Jul 22 '12 at 07:15
  • Whatever you are using to see how it is "stored in the database" is not properly displaying UTF-8, by the looks of it. Anyway, the actual bytes are important for resolving this issue; but apparently, ș is stored as the bytes 0xC8 0x99 just like it should be. – tripleee Jul 22 '12 at 07:24
  • @tripleee I'm using the phpmyadmin. – Tudor Ravoiu Jul 22 '12 at 08:18
  • @Wolfgang Stengel. Yes, I use jquery to make the ajax call. – Tudor Ravoiu Jul 22 '12 at 08:19
  • [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Jul 22 '12 at 08:24
  • possible duplicate of [how to replace special characters with the ones they're based on in PHP?](http://stackoverflow.com/q/1890854/), [How do I remove accents from characters in a PHP string?](http://stackoverflow.com/q/1017599/) – outis Jul 22 '12 at 08:28

1 Answers1

0

It could be due to the encoding of the MySQL connection. For a bug free utf8 environment, you need to set the page, the database and the mysql connection to UTF-8.

Try this function:

mysql_set_charset('utf8');

or better use mysqli:

$mysqli->set_charset("utf8");

http://php.net/manual/fr/mysqli.set-charset.php

nebulousGirl
  • 1,364
  • 2
  • 13
  • 23