json_encode in html tag

2

How do I put a json generated by php into a link tag

$array = array('a','b','c');

$json = json_encode($array);

$link = '<a href.. tag="'.$json.'">';

// tried with JSON_HEX_QUOT | JSON_HEX_TAG and does not work

    
asked by anonymous 21.03.2015 / 14:07

1 answer

2

As you want, you should use the htmlentities() function so that the double quotation marks are converted to your HTML entity :

$array = array('a','b','c');

$json = json_encode($array);

$link = '<a href.. tag="'.htmlentities($json).'">';

See example on Ideone .

    
21.03.2015 / 16:47