Json_encode and Persian words?
I use json_encode to insert an array of values (for example: <input name="ok[]">... into the database, I don’t know why it inserted Persian words like ["\u0633\u06cc\u062f \u0633\u0639\u06cc\u062f \u062f\u0627\u062f\u0627\u0634\u0632\u0627\u062f\u0647"] , it was previously inserted as: سید سعید داداشزاده .
The database output ( select * from tabla ... ) to json_encode is: [\"\\u0633\\u06cc\\u062f \\u0633\\u0639\\u06cc\\u062f \\u062f\\u0627\\u062f\\u0627\\u0634\\u0632\\u0627\\u062f\\u0647\"]"
In my table (database), the sorting of this row is utf8_general_ci ?
What am I doing for print("output of database") Persian words like سید سعید داداشزاده ?
json_encode encodes all non-ascii characters with a note \uXXXX . This is not a problem because any json decoder and javascript recognize this notation:
json_decode('["\u0633\u06cc\u062f \u0633\u0639\u06cc\u062f \u062f\u0627\u062f\u0627\u0634\u0632\u0627\u062f\u0647"]'); // array('سید سعید داداشزاده') However, it seems that the row you get from the database is reset. Either it was double-shielded before being inserted into the database, or you have magic_quotes_runtime turned on. Use stripslashes in json string before using json_decode to avoid it:
json_decode(stripslashes('[\"\\u0633\\u06cc\\u062f \\u0633\\u0639\\u06cc\\u062f \\u062f\\u0627\\u062f\\u0627\\u0634\\u0632\\u0627\\u062f\\u0647\"]')); you can use this method:
https://gist.github.com/MahdiMajidzadeh/88407f4c33a294cae29ed1493332d7c0
:)))))