How to convert json data into utf8 by php
This article mainly introduces "how php converts json data into utf8". In daily operation, I believe many people have doubts about how php converts json data into utf8. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "php how to convert json data into utf8". Next, please follow the editor to study!
Php converts json data into utf8: 1, create a PHP sample file; 2, save the json array as utf8 through "json_encode ($xm_json,JSON_UNESCAPED_UNICODE);"
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
How does php convert json data into utf8?
Php json is saved as utf8
Json_encode ($xm_json,JSON_UNESCAPED_UNICODE); / / Save the json array as utf8
The json saved by php json_encode is utf8
Json_encode
(PHP 5 > = 5.2.0, PHP 7, PHP 8, PECL json > = 1.2.0)
Json_encode-JSON encoding of variables
Description
Json_encode (mixed $value, int $options = 0, int $depth = 512): string | false
Returns a string containing the JSON representation of the value value.
The encoding is affected by the passed-in options parameters, and the encoding of floating-point values depends on serialize_precision.
Parameters.
Value
The value to be encoded can be any data type except the resource type.
All string data must be encoded as UTF-8.
Note:
PHP implements a superset of JSON, refer to »RFC 7159.
Options
A binary mask consisting of the following constants: JSON_FORCE_OBJECT, JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_NUMERIC_CHECK, JSON_PARTIAL_OUTPUT_ON_ERROR, JSON_PRESERVE_ZERO_FRACTION, JSON_PRETTY_PRINT, JSON_UNESCAPED_LINE_TERMINATORS, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, JSON_THROW_ON_ERROR. For more information about JSON constants, please see the JSON constants page.
Depth
Sets the maximum depth. Must be greater than 0.
Return value
Returns JSON-encoded string on success or false on failure.
At this point, the study on "how php converts json data into utf8" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!