We need two Codeigniter functions. The first should be passed a text string, and be able to identify any dates contained within it, in any of the formats listed below. It should then be able to extract the date, pass it to the second function (see below), and then replace the date in the string, with the value returned from the other function.
The second when called, needs accepts two parameters the first is a date, in one of the following formats, the second is the output type - which has three possible options 'F' for full date (i.e. 1st April 2011), 'C' for compact date (i.e. 01-04-2011 dd-mm-yyyy), or 'M' for MySQL format date (2011-04-01 yyyy-mm-dd). The function should return a single value, of the date in the format requested.
The function needs to be able to recognise the correct day, month and year and undertake the appropriate conversion. In all the examples below the day is the first value, the month is the middle value, and the year is the last. All are 1st April 2011, although the function should be able to accept any calendar date, in any year.
Both should be optimised to be as efficient as possible, using the least amount of code.
An example of a text string containing a date that should be passed to the first function is:-
"Fred arrived at the hotel on 1 Apr 2011 and checked in as planned."
The first function should detect the date as '1 Apr 2011' and pass that to the second function with additional parameter of 'F' in this case, which should then return the value of 1st April 2011. The first function should then replace the date with the returned value, and return the full text string....
"Fred arrived at the hotel on 1st April 2011 and checked in as planned."
The text string may contain one or more dates, in one or more formats.
Possible different date formats:
01.04.11
01.4.11
1.04.11
01.04.2011
01.4.2011
1.4.2011
1.04.2011
01-04-11
01-4-11
1-04-11
01-04-2011
01-4-2011
1-4-2011
1-04-2011
01/04/11
01/4/11
1/04/11
01/04/2011
01/4/2011
1/4/2011
1/04/2011
1 Apr 2011
01 Apr 2011
1 Apr 11
01 Apr 11
01 April 2011
1 April 2011
01 April 11
1 April 11
01/April/2011
1/April/2011
01/April/11
1/April/11
01/Apr/11
01/Apr/2011
1/Apr/11
1/Apr/2011
1st April 11
1st Apr 11
01/04.11
01/4.11
1/04.11
01/04.2011
01/4.2011
1/4.2011
1/04.2011
01 04 11
01 4 11
1 04 11
01 04 2011
01 4 2011
1 4 2011
1 04 2011