E
E
ebanytiu_lis2017-08-16 16:00:44
PHP
ebanytiu_lis, 2017-08-16 16:00:44

How to output JSON as a file through PHP?

I need to output JSON through PHP without . This code will produce something like:<html>
echo(json_encode($result));

<html>
  <head></head>
  <body>
    {"type": "virus", "name": "Petya"}
  </body>
</html>

And I just need {"type": "virus", "name": "Petya"}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nik Gubin, 2017-08-16
@ebanytiu_lis

Use headers:

header("Content-type: application/json; charset=utf-8");

echo json_encode($result);

D
Denis Ilinykh, 2017-08-16
@greyhard

exit(json_encode($result));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question