Question

Two things I don't deal with very well in development. Time and Languages.

I have a 'message' field that is being encrypted and stored in the DB by POSTing a JSON Object.

{
    "message": "Hello World"
}

I want my message field to be flexible enough to incorporate languages in addition to English. Something like this in Ukrainian.

{
    "message": "привет мир"
}

My DB Field is utf8_unicode_ci.

When I post the above JSON Object, my database stores the following:

\u043f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0440

My question is, what is the correct PHP function to return this string back into it's correct characters? Also, do I need to encode it before encrypting it and storing in the DB? or is the above format a correct format to decode?

Thank you

Was it helpful?

Solution

It looks like my issue was with the way I was retrieving and displaying the JSON. I was using Postman in one instance and my encoded text came out fine. But if I directed my browser to the route I would see the encoded values.

The reason for this is because Postman has the charset set to UTF8 and when I visit my route directly there is no charset being set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top