Hello,
I need a PHP function that knows to extract dates from a short text. The function will go through the text, word by word and will check if it's a date or just a word/number.
a. The function can return 3 possible solutions: NULL if no date was found, one date(if only one date was found), 2 dates if 2 dates where found.
b. If 2 dates are found the function needs to order them from earlier to later. So the first date will be earlier than the seconed one(i.e. 3/10/2013, 21/10/2013).
c. The trickier part of the function is that date format can come in number of structures. Dates can appear in any of the following: 1/3/2013, 01/03/2013, 1-3-2013, 1.3.2013. Dates can also mix in structures 01.03.13 and so on. It is possible that dates will appear in a shorter structure such as 2/10 or 2.10 in that case the function will need to add today's year. So if the function finds 2/10 it will return 2/10/2013. The function needs to know how to handle all these cases.
d. The function will receive a flag variable that will indicate the day/month positioning, There are languages that the month comes before the day so 9/10/2013 means September 10'th 2013, and there are languages that 9/10/2013 means October 9'th 2013. This will be indicated by a special flag $stucture_flag that will be sent to the function upfront(1 means day/month/year, 2 means month/day/year).
e. The dates output should be structured to fit MySQL input (2013-09-07) which means September 7'th 2013.
f. Please add proper commenting inside the code.
g. The function will receive two variables Extract_dates($text,$stucture_flag). $text will contain the text. $stucture_flag can be 1 OR 2, which tells the function about the day/month structure(as was discussed in section 4).
h. If you have any questions, let me know.
PHP, Software Architecture
0 comments:
Post a Comment