繁体   English   中英

从字符串解析日期

[英]Parse Date from String

我正在使用DOMxPath从xml文件中检索元素内部的数据...

$xml = file_get_contents('data.xml');
$dom = new DOMDocument();
@$dom->loadHTML($xml);
$domx = new DOMXPath($dom);
$entries = $domx->evaluate("//observation_time");


$arr = array();
foreach ($entries as $entry) {

  $ar6 = $entry->nodeValue;

}


echo "$ar6";

}

这是XML

<observation_time>Last Updated on Dec 1 2011, 6:47 pm EST</observation_time>

输出为:最近更新时间:2011年12月1日,美国东部标准时间下午6:47

我的问题是:如何仅从该字符串中提取日期? 使用查找?

使用此输入,您可以执行以下操作:

$time = 'Last Updated on Dec 1 2011, 6:47 pm EST';

#following line will give you date part only
$time = preg_replace('~^Last Updated on\s*~i', '', $time);

#this line will convert time to unix timestamp
$time = strtotime($time);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM