moizhb Posted August 9, 2011 Share Posted August 9, 2011 Hi there, I am running 5.2.5 on the server and 5.3.5 on my sandbox. I am using json_encode($arr, true) which works on my sandbox but doesn't work on the server since 5.2.5 doesn't allow second argument. The second argument is for parsing HTML in the array and return the json with HTML. I am trying to find out a way to make it work on the server since I cannot update the php version. Is there a way I can encode the HTML before assigning to the array or if I can get the latest definition of json_encode()? Thank you very much in advance. Quote Link to comment https://forums.phpfreaks.com/topic/244326-json-encode/ Share on other sites More sharing options...
JasonLewis Posted August 9, 2011 Share Posted August 9, 2011 The second parameter for json_encode is actually a group of options that are predefined constants. Passing true in doesn't seem correct to me? Although if it's working for you... How, exactly, is it parsing the HTML? Quote Link to comment https://forums.phpfreaks.com/topic/244326-json-encode/#findComment-1254937 Share on other sites More sharing options...
moizhb Posted August 9, 2011 Author Share Posted August 9, 2011 I agree with you. The second parameter is predefined constants. But passing true works for me. I can parse the HTML if I pass true using JSON.parse(data) on the browser but if I do not pass second parameter I see the following error on the browser. uncaught exception: Invalid JSON: I appreciate you helping me out. Thank you, Moiz Quote Link to comment https://forums.phpfreaks.com/topic/244326-json-encode/#findComment-1254939 Share on other sites More sharing options...
PFMaBiSmAd Posted August 9, 2011 Share Posted August 9, 2011 A logical true evaluates to a 1. The predefined constant JSON_HEX_TAG (currently) has the value 1. It is likely that your use of true results in - All < and > are converted to \u003C and \u003E You should use the predefined constant JSON_HEX_TAG so that your code will (always) work correctly and clearly and you can do a simple str_replace using arrays on the data to emulate what JSON_HEX_TAG does. Quote Link to comment https://forums.phpfreaks.com/topic/244326-json-encode/#findComment-1254942 Share on other sites More sharing options...
moizhb Posted August 9, 2011 Author Share Posted August 9, 2011 A logical true evaluates to a 1. The predefined constant JSON_HEX_TAG (currently) has the value 1. It is likely that your use of true results in - All < and > are converted to \u003C and \u003E You should use the predefined constant JSON_HEX_TAG so that your code will (always) work correctly and clearly and you can do a simple str_replace using arrays on the data to emulate what JSON_HEX_TAG does. Hi there, Thank you for replying. Wouldn't htmlentities() do that? I tried htmlentities but didn't work. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/244326-json-encode/#findComment-1254949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.