2012-10-01 44 views
1

如何使用cURL從該URL獲取數組? http://module.game-monitor.com/67.202.102.136:27016/data/server.phpPHP - cURL到數組?

這是我的代碼到目前爲止。

$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; 

回答

2

儘量只用PHP Type Casting(array)並取出objectToArray功能

$head = unserialize($head); 
$head = (array) $head ; 
var_dump($head); 

輸出

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) 
+0

沒關係。得到它的工作=] –

+0

查看完整代碼:http://codepad.viper-7.com/6ceAVM – Baba

+0

Oop。對不起,男人對於額外的男人是我的壞處。 –