I have a code snippet that is encoding a PHP array into json but when i am trying to parse it it gives me error because of " present in value
PHP array
$arr = array( id => 1, msg => <h1>Some text</h1> <img src="http://test.png">);
Js code
var json = JSON.parse('<?php echo json_encode($arr);?>');
When i json_encode the above error it surrounds string with double quotes that breaks my JSON.parse function. I tried using replace function but after json_encode it automatically adds double quotes surrounding the string values of object.
So i tried to replace all " with ' but it is replacing all double quotes. i am thinking can it be done by regex to replace only " in html elements or something else. I could not escape HTMl at time of saving because a large number of data is already present in the database and changing it is bit difficult.
Some text