【发布时间】:2013-04-16 13:13:28
【问题描述】:
我正在尝试从 api.hostip.info 获取有关 IP 地址的信息,但以下代码返回当前 XML 版本;
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = 'http://api.hostip.info/?ip=12.215.42.19';
$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
var_dump($xml);
如何从 URL 返回数据?
【问题讨论】:
-
不。我想从 api.hostip.info 获取信息,这样我就可以将
countryAbbrev与我拥有的函数相匹配。$xml = htmlentities($xml);顺便返回了许多没有文本的新行