简体   繁体   中英

How can I print Scandinavian characters (åäö) correctly when using MySQL and PHP MySQLi?

How do I handle Scandinavian characters when using MySQLi? Text Päivänkakkara is now printed as P\äiv\änkakkara in the browser.

I'm using the set_charset function like below when initializing the database connection:

$conn->set_charset("utf8");

The collation of the table is utf8_unicode_ci .

I managed to get the text to print correctly by using

echo json_encode($foo, JSON_UNESCAPED_UNICODE);

Then, however, I have to explicitly parse the JSON client-side. My client is written in TypeScript, so:

JSON.parse(data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM