Why is Latté = Latt?

I have a web form and login if you added Latté and POST using JSON ...

 $.ajax({ type: "POST", url: "http://"+document.domain+"/includes/rpc.php", data: {method:"add_item",item:item}, dataType: "json", timeout: 10000, success:...... 

item will display the value Latté Latté, and the corresponding JSON Latt\u00e9 , which the browser interprets as Latté . Effectively, this script is a WYSIWYG editor, so you enter the text you return. Anyhue, if I update the text, it is pulled from mysql and issued as Latté? . So, I assume MYSQL is not the correct sort?

Additional information - database editing request

UPDATE menu_items SET description = 'Latté' WHERE item_id = '742'

JSON response

{"description":"Latt\u00e9","id":"#recordsArray_742"}

+4
source share
4 answers

To be precise, sorting is a way to compare and sort strings. It is related to a character set, but your problem is a character set problem , not a sorting problem.

A character set is a set of characters and encodings. Sorting is a set of rules for comparing characters in a character set .

The first thing you should know is that the character you are using is using . Are you using UTF-8 or LATIN1 or others?

After that, I will try to derive the correct header from the PHP script by creating a JSON string. For example, for UTF-8:

 header('Content-type: application/json; charset=utf-8'); 

This can already solve your problem if we do not need to look deeper at how you connect to the database and how you manage your data. Let me know in case which libraries or MySQL frame you use to connect to db, and place the appropriate source code.

+3
source

It could be a MySQL sort.

It can also be HTTP encoded.

Or you can use string functions in PHP that are not multibyte.

Such an error can occur at many points through a tool chain.

+2
source

Any sorting of the database is incorrect or the DBAL you are using (PDO?).

0
source

Use utf8_encode () around your selected values ​​in your PHP server before you output it

0
source

All Articles