Answer the question
In order to leave comments, you need to log in
How to pass layout via JSON to Javascipt from PHP?
I ate all my brains already =)
In general, the authors who wrote the site obviously did not know that it is very unsafe to use simultaneously in a language file:
1. single quotes
2. double quotes
3. line
breaks 4. layout and tags
5. percent signs in symbols %s, %d and so on for sprintf
Now the json_encode($data, JSON_HEX_QUOT) function does not cope with the direct task.
I take it, I turn it into JSON, then I output it in the template as a
php function:
$data = get_langs();
$json = json_encode($data, JSON_HEX_QUOT);
$smarty->assign('json', $json);
<script>
App.Langs.addJson('{$json}');
</script>
str_replace("\"", '\"', str_replace("'", '\'', json_encode($data)))
Answer the question
In order to leave comments, you need to log in
php.net/manual/en/function.base64-encode.php
And in JS:
PS:
$json = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE); ///вот так - не работает?!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question