1

我如何使用 cURL 从这个 URL 取回一个数组?http://module.game-monitor.com/67.202.102.136:27016/data/server.php

到目前为止,这是我的代码。

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

1 回答 1

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)
于 2012-10-01T01:51:02.210 回答