…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
Leave a Reply
My name is Joey Nelson. I'm a web developer living in Raleigh, NC and working with Node.js, MongoDB, Ruby, PHP, jQuery and some other stuff. More about me.
HOW COULD YOU JOEY, HOW COULD YOU