Home >Backend Development >PHP Tutorial >json_encode supports Chinese after adding options parameter, json_encodeoptions_PHP tutorial
-------------------------- -------------------------------------------------- --------------------------
<span>header</span>('content-type:text/html;charset=utf-8'<span>); </span><span>$a</span> = '中文'<span>; </span><span>echo</span> json_encode(<span>$a</span>);<span>//</span><span>5.3版本以前,无参数情况输出 "\u4e2d\u6587"</span> <span>echo</span> json_encode(<span>$a</span>, JSON_UNESCAPED_UNICODE); <span>//</span><span> "中文"</span>
@黑eyedpoet
Your understanding is wrong. This is JS code. In fact, the built-in JS object is very small. You may put what you see into the programming framework and understand JS before learning programming methods for a certain framework. characteristic. You need to understand the object better under JS and it will not be difficult to understand the above code.
(1)$. extension (options, customoptions), seen from the code itself, $. Extend is not defined here, so there's no answer to what exactly it does. But in commonly used programming frameworks such as jQuery, this function mainly implements the properties and methods of objects from customoptions to the options object, which is what you call "expansion".
(2) JS type has weak or no language restrictions, so the parameter can be any type of object, usually, generally extending the combined object, including properties and functions of the object, so that you can see what it is " It is normal for objects to extend" functionality or "extend" other characteristics.
(3), choose your code to define the object (when the object is defined by {} object) instead of JSON, JSON refers to the string expression of the object, there is no string JSON format, you need to learn Understand the different definitions of writing JSON strings in JS code and programs. So, through the definition of the function, but no JSON here.
Isn't this because the two Chinese characters were encoded into unicode format after you encoded it?
The 'Shia' in unicode encoding format is \u5e0c\u4e9a