Answer the question
In order to leave comments, you need to log in
How to solve json_encode output problem?
Hello.
I output JSON in PHP in this way: echo json_encode($data, JSON_UNESCAPED_UNICODE);
Nothing extra before and after json_encode is output, without this line the server response is empty.
On the home server, everything works as it should, on the hosting, some garbage is added to the response, it looks something like this:
1221d
{"user":{ ... // тут собственно строка с JSON
0
//конец ответа
file_put_contents(Yii::app()->basePath.'/logs/test.json', json_encode($data, JSON_UNESCAPED_UNICODE));
Answer the question
In order to leave comments, you need to log in
$json = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $json);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question