1

I am using a latin1_swedish_ci database to store json_encoded arrays. Previously, I have made these arrays in javascript by using JSON.stringify().

I am now loading these arrays, editing them with PHP and saving them again. In order to do so, I am using json_decode() and json_encode() functions.

However, this converts the charset from latin1 to utf-8, and the foreign letters are changed after saving the altered arrays back to the database.

What would be the best way to avoid this? Should I simply convert the altered arrays from utf-8 to latin1 before saving them, and how would I do so?

Thanks!

user2806026
  • 787
  • 3
  • 10
  • 24
  • You need to ensure the entire application is set to utf8. Never mix charset. Also, storing arrays in a database in a single cell sounds like a poor design pattern. You should learn about database normalization – Qirel Apr 10 '17 at 08:29
  • Thanks for your suggestion. So I should convert my databases to utf8 and use this everywhere? – user2806026 Apr 10 '17 at 08:32
  • Database, connection, php/html headers, file encoding, all of it. I've posted an [**answer with a "sandwich list"**](http://stackoverflow.com/a/31899827/4535200) before, and there's also [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) which is a lot more detailed. – Qirel Apr 10 '17 at 08:34

0 Answers0