Escaping/encoding single quotes in JSON encoded HTML5 data attributes

You need to HTML escape data echoed into HTML:

printf('<article data-tags="%s">',
    htmlspecialchars(json_encode(array('html5', ...)), ENT_QUOTES, 'UTF-8'));

Leave a Comment