M
M
makboriska2022-01-03 21:59:59
PHP
makboriska, 2022-01-03 21:59:59

How to create name.json file in php?

Hello! I get a json array in response to an api request, I need to save it, how can I do this?) Stupid question, but I didn’t find anything on the Internet, maybe I’m writing something wrong.

This is how I get data

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://www.booking-manager.com/api/v2/companies');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');


$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Authorization: b5cf6d00534c3a0a3ff1a4';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2022-01-03
@lolzqq

$filename='your path where you want to save the file + file name';
$data='your json text';
file_put_contents($filename,$data);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question