herghost Posted March 13, 2010 Share Posted March 13, 2010 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 More sharing options...
herghost Posted March 13, 2010 Author Share Posted March 13, 2010 Ok, I now have this: print $result; $str = $result; $arr1 = str_split($str); print_r(array_splice($arr1,2,3,4)); Which outputs: [0] => o [1] => n [2] => e Now how would I turn this into : $a = [0][1][2]; ? Thanks Link to comment https://forums.phpfreaks.com/topic/195096-curl-help/#findComment-1025546 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.