Answer the question
In order to leave comments, you need to log in
JSON.parse not working with apostrophe?
I want to pass some data to the page from PHP to JS
There is a code
<script>
let items = []
items.push(JSON.parse('<?= json_encode($item) ?>'))
</script>
{"param1": "value1", "param2": "SYMBOL'symbol"}
json_encode(str_replace("'", "\'", $item))
{"param1": "value1", "param2": "SYMBOL\\'symbol"}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question