August 12, 2007

I’m not proud of this

…but I didn’t have much of a choice:

function parse_date_from_string($string=""){
	$month_names = array("", "January","February","March","April","May","June","July","August","September","October","November","December");
	$regex = "/(\d{1,2})[-|\/|\.](\d{1,2})[-|\/|\.](\d{2}|\d{4})/";
	$date = array();
	if(preg_match($regex, $string, $matches)){
		$month = preg_replace("/^0/", "", $matches[1]);
		$date['month'] = $month_names[$month];
		$date['day'] = $matches[2];
		if(strlen($matches[3]) == 2) $matches[3] = "20" . $matches[3];
		$date['year'] = $matches[3];
		$date['string'] = trim(preg_replace($regex, "", $string));
	}
	return $date;
}

1 Response

  1. 1 JIMMY SMITS

    HOW COULD YOU JOEY, HOW COULD YOU

Leave a Reply