I\'m not sure how to go about this one. I\'m building a calendar in PHP and need users to be able to add a repeating event that follows the following rule:
Last [DOW
For everything date-related that you can express in proper English but have a hard time expressing using numbers, strtotime is your best friend.
echo strtotime("last Monday of June 2011");
This returns a timestamp that you can use as the second parameter to date and the likes to get a proper, human-readable date. Since it's a built-in function written in C, this solution is also much faster than almost anything else you could come up with written in PHP (though I'm quite sure it wouldn't matter much in a real-world scenario).
So assuming you have $month=4
, $dow=3
and $year=2011
, you'll need an array mapping $month
values to their English textual representations and another array mapping $dow
values to their textual representations.