Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/244326-json-encode/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/244326-json-encode/#findComment-1254939
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/244326-json-encode/#findComment-1254942
Share on other sites

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,

 

Link to comment
https://forums.phpfreaks.com/topic/244326-json-encode/#findComment-1254949
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.