Monthly Archives: February 2012

Max days in a month with PHP

function get_max_days_in_month($month, $year) {
 
	$getdate = getdate(mktime(null, null, null, $month + 1, 0, $year));
 
	return $getdate['mday'];
}

Last weekday in a month with PHP

function get_last_weekday_in_month($month, $year) {
 
	$getdate = getdate(mktime(null, null, null, $month + 1, 0, $year));
 
	return $getdate['wday'];
}

First weekday in a month with PHP

function get_first_weekday_in_month($month, $year) {
 
	$getdate = getdate(mktime(null, null, null, $month, 1, $year));
 
	return $getdate['wday'];
}

chmod recursive

function chmod_r($path, $filemode) {
 
	if (!is_dir($path)) {
 
  		return chmod($path, $filemode);
 	}
 
 	$dh = opendir($path);
 
 	while ($file = readdir($dh)) {
 
	  if ($file != '.' && $file != '..') {
 
		$fullpath = $path.'/'.$file;
 
	   	if (!is_dir($fullpath)) {
 
	    		if (!chmod($fullpath, $filemode)) {
 
	     			return false;
	    		}
 
	   		} else {
 
	    		if (!chmod_r($fullpath, $filemode)) {
 
	     			return false;
	    		}
	   	}
	  }
	}
 
 	closedir($dh);
 
 	if (chmod($path, $filemode)) {
 
  		return true;
 	}
 
 	return false;
}

usage:

chmod_r('your/path', 0777);
Page 1 of 11