Is date

Wednesday, March 17th, 2010

See if a string is actually a date (used for friendly urls mostly)

  1. // See if a string from the url is an actual date
  2. function isDate($var){
  3.         $time = strtotime(str_replace('-', ' ', $var));
  4.         if($time){
  5.                 if(strlen($var) == 8){
  6.                         return Array('month', $var, $time);
  7.                 }elseif(strlen($var) == 11){
  8.                         return Array('day', $var, $time);
  9.                 }
  10.         }
  11.         return false;
  12. }

Display clean php code for copying

// See if a string from the url is an actual date
function isDate($var){
	$time = strtotime(str_replace('-', ' ', $var));
	if($time){
		if(strlen($var) == 8){
			return Array('month', $var, $time);
		}elseif(strlen($var) == 11){
			return Array('day', $var, $time);
		}
	}
	return false;
}