0

我正在使用cURL 和 WHOIS 查询来检索不同网站的注册信息。

问题是 WHOIS 查询返回带有不同格式日期的字符串。

我想使用 preg_match将创建日期和到期日期提取到单独的数组中,例如:

$creation = array(year, month, day);
$expiration = array(year, month, day);

不同的字符串输出有以下格式:

    expires: 2014-01-10 14:00:27
    created: 2012-01-10 15:00:28

    Creation Date: 25-Mar-2010  
    Expiration Date: 25-Mar-2013

    Record created:     14/04/2012
    Record expires:     14/04/2013

    Record created on.......: Mar 05, 2001  
    Record expires on.......: Mar 05, 2013

    Created on..............: 1997-09-15.
    Expires on..............: 2020-09-13.

    Expiration Date: 2015-12-26 19:18:07
    Creation Date:   2003-12-26 19:18:07

关于如何使用 preg_match 提取日期的任何线索?

注意:我尝试过使用 PHP Whois API 类,但效果不佳,以及不同的 XML API,但数据不完整。

4

1 回答 1

0

我实际上制定了这个功能:

function creationdate($data)
{

if(preg_match('/Creation Date:/i',$data) == true){
    $csta = strpos($data, 'Creation Date:', 0)+14;
    $cstb = strpos($data, 'Creation Date:', 0)+27;
    $date = trim(substr($data, $csta, $cstb-$csta));
return strtotime($date);};

if(preg_match('/Record created:/i',$data) == true){
    $csta = strpos($data, 'Record created:', 0)+15;
    $cstb = strpos($data, 'Record expires:', $csta)-2;
    $date = substr($data, $csta, $cstb-$csta);
    $date = explode('/', $date);
    $date = $date[0] .'-'. $date[1] .'-'. $date[2];
return strtotime($date);};

if(preg_match('/Created on..............:(.*?)\./i',$data,$date) == true){
return strtotime($date[1]);};

if(preg_match('/Record created on.......:/i',$data) == true){
    $csta = strpos($data, 'Record created on.......:', 0)+26;
    $cstb = strpos($data, 'Record expires on.......:', $csta)-5;
    $date = substr($data, $csta, $cstb-$csta);
return strtotime($date);};

if(preg_match('/created:/i',$data) == true){
    $csta = strpos($data, 'created:', 0)+9;
    $cstb = strpos($data, 'created:', 0)+20;
    $date = trim(substr($data, $csta, $cstb-$csta));
return strtotime($date);};

return '-';

}
于 2012-11-24T09:42:06.913 回答