Solution: #PHP: Handling json_encode data in html data attribute


Updated September 2, 2015 ● 3,546 views

If you are passing JSON encoded data to HTML data attribute, you need to properly escape the data and handle special characters.

Do the following when passing JSON encoded data in HTML data attribute:

<a href="javascript:void(0);" data-content="<?php echo htmlspecialchars(json_encode($comment), ENT_QUOTES, 'UTF-8'); ?>">TEST ACTION</a>

 

0 Comments