Hiermit wandelst du einen (fast) beliebigen Datumsstring in unixtime um.
function parse_date($strDate)
{
if($strDate != "")
{
$month = array( 'januar' => 1,
'februar' => 2,
'märz' => 3,
'april' => 4,
'mai' => 5,
'juni' => 6,
'july' => 7,
'august' => 8,
'september' => 9,
'oktober' => 10,
'november' => 11,
'dezember' => 12 );
// funtion tryes to interpret date and returns unixtime.
// if interpreting fails, it return -1
$strDate = strtolower($strDate);
$strDate = trim($strDate);
$response = -1;
// *** ISO 8601 - 1970-09-17
if (preg_match("/^(\d{2,4})-(\d{1,2})-(\d{1,2})$/",$strDate, $regex))
{
if(checkdate($regex[2], $regex[3], $regex[1]))
$response = mktime(0,0,0,$regex[2], $regex[3], $regex[1]);
}
// with time
if (preg_match("/^(\d{2,4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2})$/",$strDate, $regex))
{
if(checkdate($regex[2], $regex[3], $regex[1]))
$response = mktime($regex[4],$regex[5],0,$regex[2], $regex[3], $regex[1]);
}
// *** german format - 17.09.1970 and 17.09.70
elseif (preg_match("/^(\d{1,2}).(\d{1,2}).(\d{2,4})$/",$strDate, $regex))
{
if(checkdate($regex[2], $regex[1], $regex[3]))
$response = mktime(0,0,0,$regex[2], $regex[1], $regex[3]);
}
// with time
elseif (preg_match("/^(\d{1,2}).(\d{1,2}).(\d{2,4}) (\d{1,2}):(\d{1,2})$/",$strDate, $regex))
{
if(checkdate($regex[2], $regex[1], $regex[3]))
$response = mktime($regex[4], $regex[5],0,$regex[2], $regex[1], $regex[3]);
}
// * U.S. writeing - 9/17/72
elseif (preg_match("/^(\d{1,2}).(\d{1,2}).(\d{2,4})$/",$strDate, $regex))
{
if(checkdate($regex[1], $regex[2], $regex[3]))
$response = mktime(0,0,0,$regex[1], $regex[2], $regex[3]);
}
// with time
elseif (preg_match("/^(\d{1,2}).(\d{1,2}).(\d{2,4}) (\d{1,2}):(\d{1,2})$/",$strDate, $regex))
{
if(checkdate($regex[1], $regex[2], $regex[3]))
$response = mktime($regex[4],$regex[5],0,$regex[1], $regex[2], $regex[3]);
}
// * "2k format" - 23.11.2k2
elseif (preg_match("/^(\d{1,2}).(\d{1,2}).(\dk\d)$/",$strDate, $regex))
{
$regex[3] = str_replace("k", "00", $regex[3]);
if(checkdate($regex[2], $regex[1], $regex[3]))
$response = mktime(0,0,0,$regex[2], $regex[1], $regex[3]);
}
// with time
elseif (preg_match("/^(\d{1,2}).(\d{1,2}).(\dk\d) (\d{1,2}):(\d{1,2})$/",$strDate, $regex))
{
$regex[3] = str_replace("k", "00", $regex[3]);
if(checkdate($regex[2], $regex[1], $regex[3]))
$response = mktime($regex[4],$regex[5],0,$regex[2], $regex[1], $regex[3]);
}
// standard-format 23 Mai 2002, 13:30:30 (GMT)
elseif (preg_match("/^(\d{1,2}) ([\w|ä|ö|ü]*?) (\d{2,4})\, (\d{1,2}):(\d{1,2}):(\d{1,2}) \((\w*?)\)/",$strDate, $regex))
{
if(empty($month[$regex[2]])) print_r ($regex);
$regex[2] = $month[$regex[2]];
if(checkdate($regex[2], $regex[1], $regex[3]))
$response = mktime($regex[4],$regex[5],$regex[6], $regex[2], $regex[1], $regex[3]);
}
// * today or heute
elseif ($strDate == 'heute' or $strDate == 'today')
{
$response = mktime(0,0,0,sds_date("m"), sds_date("d"), sds_date("Y"));
}
// * now or jetzt
elseif ($strDate == 'now' or $strDate == 'jetzt')
{
$response = time();
}
}
else
{
$response = "";
}
return $response;
}