json_encode in html tag

Asked

Viewed 506 times

2

How do I place a json generated by php in 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

  • yes, punch it breaks with double quotes generated by json_encode

1 answer

2


In the form you intend, you must make use of the function htmlentities() so that double quotes are converted to your HTML entity:

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

$json = json_encode($array);

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

See example in Ideone.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.