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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?