Escaping/encoding single quotes in JSON encoded HTML5 data attributes

后端 未结 2 420
栀梦
栀梦 2020-12-01 07:54

In PHP, I use json_encode() to echo arrays in HTML5 data attributes. As JSON requires - and json_encode() generates - values encapsulated by double

2条回答
  •  情话喂你
    2020-12-01 08:09

    You need to HTML escape data echoed into HTML:

    printf('
    ', htmlspecialchars(json_encode(array('html5', ...)), ENT_QUOTES, 'UTF-8'));

提交回复
热议问题