0

I am sending some data from a view to controller in php. I am using json_encode while sending the data and using json_decode at the other hand. The whole thing is working fine but when I use some special character in the data like single quote or double quote it fails and no data is received. Is there any way to fix this issue? I have tried using serialize and unserialize with base64 encoding, it worked for me but it's quite slow even with just few records.

Note: The $data is a multidimensional array

base64_encode(serialize($data)) unserialize(base64_decode($data))

1 Answers1

0

If you encode the json in an HTML tag attribute using PHP, you should additionally encoding the html entities using the htmlentities function. When sending the data, you can either decode the entities using javascript or using php using html_entity_decode, then you can decode the json.

maalls
  • 749
  • 8
  • 20