Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use PHP's json_encode function's second param ( the bitmasks )

Tags:

json

php

PHP's json_encode function as a second optional param ( bitmasks ). Can someone explain to me what they're for and when I should use them and why?

Thanks

like image 685
Jason Avatar asked Nov 15 '22 07:11

Jason


1 Answers

The purpose is to get rid of special character in the JSON output. In certain situation the special characters may have other meanings and you just want to pass the JSON through without making use of any of those.

Suppose you want to send the json inside some XML. You don't want any < in there messing with the xml. So you just use the option to get rid of those so it doesn't cause any problems.

like image 114
Winston Ewert Avatar answered Nov 17 '22 05:11

Winston Ewert