douzhan8303 2014-02-20 07:51
浏览 24
已采纳

从earthtool获取日期 - PHP和XML解析

I found this web service which provides the date time of a timezone. http://www.earthtools.org/timezone-1.1/24.0167/89.8667

I want to call it & get the values like isotime with php.

So I tried

$contents = simplexml_load_file("http://www.earthtools.org/timezone-1.1/24.0167/89.8667");

$xml = new DOMDocument();
$xml->loadXML( $contents );

AND also with

file_get_contents

With file_get_contents it gets only a string of numbers not the XML format. Something like this

1.0 24.0167 89.8667 6 F 20 Feb 2014 13:50:12 2014-02-20 13:50:12 +0600 2014-02-20 07:50:12 Unknown 

Nothing worked. Can anyone please help me that how can I get the isotime or other values from that link using PHP?

  • 写回答

1条回答 默认 最新

  • dongshi2836 2014-02-20 08:09
    关注

    Everything works):

    $url = 'http://www.earthtools.org/timezone-1.1/24.0167/89.8667';
    $nodes = array('localtime', 'isotime', 'utctime');
    $cont = file_get_contents($url);
    $node_values = array();
    if ($cont && ($xml = simplexml_load_string($cont))) {
        foreach ($nodes as $node) {
            if ($xml->$node) $node_values[$node] = (string)$xml->$node;
        }
    }
    
    print_r($node_values);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料