Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Flags for json_encode()

Tags:

json

php

How do I use multiple flags for the php json_encode()-function?

json_encode($array, JSON_PRETTY_PRINT, JSON_UNESCAPED_UNICODE); 

This doesn't work - as just the first flag will be done an the second will be ignored.

like image 358
user3142695 Avatar asked Aug 31 '15 12:08

user3142695


People also ask

What does the PHP function json_encode () do?

The json_encode() function is used to encode a value to JSON format.

What is the difference between json_encode and json_decode?

PHP json_decode() and json_encode(): Summary JSON can be handled by using inbuilt PHP functions. For example, a PHP object might be turned into JSON format file using PHP json_encode() function. For the opposite transformation, use PHP json_decode() . PHP arrays are not supported by XML but can be converted into JSON.

How do I encode a string in JSON?

In jQuery you can use the following code to encode the json: var data = {"key1":"value1", "key2":"value2","key3":"value3",...}; $. each(data,function(index,value)){ alert(index+" | "+value); });

What does json_decode return?

The json_decode() function can return a value encoded in JSON in appropriate PHP type. The values true, false, and null is returned as TRUE, FALSE, and NULL respectively. The NULL is returned if JSON can't be decoded or if the encoded data is deeper than the recursion limit.


1 Answers

You use a bitmask, as specified in http://php.net/manual/en/function.json-encode.php:

json_encode($array, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE); 

This will add the binary values of JSON_PRETTY_PRINT and JSON_UNESCAPED_UNICODE with the binary OR operator.

like image 153
Byte Welder Avatar answered Sep 21 '22 01:09

Byte Welder