S
S
Skinner2015-06-16 15:45:46
PHP
Skinner, 2015-06-16 15:45:46

How to save JSON string to file?

Tell me please!
There is a script that pulls information and I need to
add in it so that Jason would save the string that we get to the file with
the code -
"function getHash($reset = false) {
$json = file_get_contents(RMURL);
$response = json_decode($json);
$response = explode("+", $response->result);
$string = (int)array_shift($response);
$hexa8ID = hexa8($string);
$currentTime = (string)floor(time() / 1000 );
$hexa8Time = hexa8($currentTime);
$hash = hexa8($string)
.hexa8($currentTime)
.hexa8(crc32((string)$currentTime.(string)crc32('secret')));
return $ hash;
}
function runQuery($param) {
$hash = getHash();
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, BASEURL.'runList?session_signature='.$hash);
$opt = array('Authorization' => 'UB '.$hash);
$param = array( $param);
curl_setopt($curl, CURLOPT_HTTPHEADER, $opt);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($param));
$res = curl_exec($curl);
$result = json_decode($res);
return $result;
}"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Valery Ryaboshapko, 2015-06-16
@valerium

Please format your code in a human way. There is only a declaration of two functions and not a single call to them. But in general, something like this line will help you.

file_put_contents('/path/to/my.json', json_encode($data));

A
Alexander N++, 2015-06-16
@sanchezzzhak

curl has a setting to save the result to a file

$dest_file = @fopen($file, "w");	
curl_setopt($ch,CURLOPT_FILE, $dest_file);
curl_setopt($ch,CURLOPT_HEADER, 0);
curl_exec($ch);
fclose($dest_file);

S
SagePtr, 2015-06-16
@SagePtr

file_put_contents

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question