Reputation: 987
How could I use cURL to get back an array from this URL? http://module.game-monitor.com/67.202.102.136:27016/data/server.php
This is my code so far.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://module.game-monitor.com/67.202.102.136:27016/data/server.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false); // remove body
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$head = unserialize($head);
$head = objectToArray($head);
$head["query_time"] = str_ireplace('ms', '', $head["query_time"]);
return $head;
Upvotes: 1
Views: 3955
Reputation: 95101
Try just use PHP Type Casting (array)
and remove the objectToArray
function
$head = unserialize($head);
$head = (array) $head ;
var_dump($head);
Output
array
'ip' => string '67.202.102.136' (length=14)
'port' => string '27016' (length=5)
'player' => int 0
'maxplayer' => int 14
'name' => string 'Another www.cogameservers.com CSGO Server' (length=41)
'premium' => string '0' (length=1)
'link' => string 'http://www.game-monitor.com/csgo2_GameServer/67.202.102.136:27016/Another_www.cogameservers.com_CSGO_Server.html' (length=112)
'error' => int 0
'query_time' => string '0ms' (length=3)
Upvotes: 2