Json encoding strings with spaces Json encoding strings with spaces wordpress wordpress

Json encoding strings with spaces


Use htmlentities to encode the json. It will encode all the " which was breaking attribute.

echo '<h1 id="stumped" data-stumped="'.htmlentities(json_encode($data_ar)).'">test</h1>';