In PHP you can pass the t format character to the date() function in order to get the number of days in the month. Since this number also happens to be the date of the last day of the month, you can use this to your advantage:
Get the last day of the current month:
Get the last day of the month a timestamp falls in: