Jump to content

Curl Help


herghost

Recommended Posts

Hi all,

 

I have a curl string that prints the result, is there a way to split the string and turn it into variables?

 

Basically my query returns 3 values from my whm server, giving me the load average over 1, 5 and 15 seconds, the result is printed like this

{"one":"0.55","five":"1.14","fifteen":"1.19"}

 

How could I turn this into:

<?php
$1second = '0.55';
$5second = '1.14';
$15second = '1.19';

 

The code used to create the query is:

<?php
include('serverauth.php');

$query = "https://" . $ip . ":2087/json-api/loadavg";



$curl = curl_init();	
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);		
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);		
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);		
$header[0] = "Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$whmhash);	
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);		
curl_setopt($curl, CURLOPT_URL, $query);			
$result = curl_exec($curl);							
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
}
curl_close($curl);

print $result;
?>

 

Hope that makes sense!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/195096-curl-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.