Esta é uma simples dica para quem está rodando um script em um server que não tenha a função cal_days_in_month() habilitada. Para quem não sabe esta função retorna a quantidade de dias que um determinado mês possui, nós informamos o padrão do calendário (constantes PHP), o mês e o ano.

Abaixo duas funções que encontrei que também retornam a quantidade de dias, apenas passando mês e ano. Para a primeira função eu não salvei aonde encontrei, na segunda os créditos estão mantidos.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function days_in_month_($month, $year)
{
   if(checkdate($month, 31, $year)) return 31;
   if(checkdate($month, 30, $year)) return 30;
   if(checkdate($month, 29, $year)) return 29;
   if(checkdate($month, 28, $year)) return 28;
   return 0; // error
}
 
/*
 * days_in_month($month, $year)
 * Returns the number of days in a given month and year, taking into account leap years.
 *
 * $month: numeric month (integers 1-12)
 * $year: numeric year (any integer)
 *
 * Prec: $month is an integer between 1 and 12, inclusive, and $year is an integer.
 * Post: none
 */
// corrected by ben at sparkyb dot net
// posted by David Bindel in php.net
function days_in_month($month, $year) { 
   return date('t', mktime(0, 0, 0, $month+1, 0, $year)); 
}