How to solve the problem of Chinese garbled code from php array to json
This article mainly explains "how to solve the problem of converting php array to json Chinese garbled code". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to solve the php array to json Chinese garbled problem" it!
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the problem of Chinese garbled code from php array to json?
Transcode each element in the array with urlencode () and then convert it to json with json_encode (), and decode it with json_decode ().
Example:
Foreach ($result as $keys = > $value) / contains a two-dimensional array of Chinese $result to json, and the internal elements of the array are converted to urlencode to ensure that the Chinese characters are not garbled {foreach ($value as $key= > $column) {$testJSON [$keys] [$key] = urlencode ($column);} var_dump (json_encode ($testJSON)); / / to json $result = urldecode ($testJSON) / / turn back to the array here. I believe you have a deeper understanding of "how to solve the problem of how to convert php array to json Chinese garbled code". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!