Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an annoying problem with a database query to mssql. If the result contains special characters like the german '?', I cannot use json_encode to get the result as json correctly.

json_last_error return 5 which is equal to JSON_ERROR_UTF8. I guess the database does not return the values as UTF-8 encoded. The database collection is *Latin1_General_CI_AS* and the affected columns are varchars.

The php mssql.charset configuration has no effect.

I read that mysql users could use mysql_query('SET CHARACTER SET utf8'); to encode the return values correctly. What can I do, to get the values correctly for mssql?

Hint - I cannot change the anything at the database.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
198 views
Welcome To Ask or Share your Answers For Others

1 Answer

Before you JSON encode, use utf8_encode() around the string.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...