Escaping/encoding single quotes in JSON encoded HTML5 data attributes

后端 未结 2 414
栀梦
栀梦 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:21

    or use the build-in option:

    json_encode(array('html5', ...), JSON_HEX_APOS)
    

    you can check it up in the manual: http://php.net/manual/en/json.constants.php#constant.json-hex-apos

提交回复
热议问题