I have an array in php that I am parsing to a javascript. My problem is that some of the strings in the array contain ampersands, and they become &
instead of &
in the javascript. Here is a simple example to illustrate my issue:
<? $titles = json_encode(array("H&M", "Tesco")); ?>
<script>
var titles = <? echo $titles; ?>;
console.log(titles[0]);
</script>
the log reads:
H&M