Page 1 of 1

[56K WARN] help with: Notice: Undefined offset: 2 in ...

Posted: Wed Nov 07, 2007 6:09 am
by Tomino23
Hi there. how are you guys? I have some small trouble with a piece of php code, and as I am just learning php, I cant solve it by myself :/

this Notice is shown when I hide all events on my page:

Code: Select all

valid since:
Notice: Undefined offset: 2 in E:\www\balfornet\resources\functions.php on line 3744
Notice: Undefined offset: 1 in E:\www\balfornet\resources\functions.php on line 3744
00.00.0000 till:
Notice: Undefined offset: 2 in E:\www\balfornet\resources\functions.php on line 3744
Notice: Undefined offset: 1 in E:\www\balfornet\resources\functions.php on line 3744
00.00.0000
when I have events (someone create an event), then it looks like this:
Image

but when I hide this event (in my admin panel), then it will do this:
Image

here is the part of code where the notice is pointing:

Code: Select all

<?
	/**
	* @desc		format date for MySQL
	* @param	string
	* @return	string
	*/
	function formatDateToMySQL($dateString, $short=false) {
		//if ( validDateFormat($dateString) ) {
			$dateArr = split('[-,/,.]', $dateString);
			if ($short == true) {
				return sprintf("%04d-%02d", $dateArr[1] , $dateArr[0]);
			} else {
				return sprintf("%04d-%02d-%02d", $dateArr[2] , $dateArr[1] , $dateArr[0]);
			}
		//} else {
		//	return $dateString;
		//}

	}

	/**
	* @desc		format date for UK display
	* @param	string
	* @return	string
	*/
	function formatDateToUK($dateString, $short=false) {
		//if ( validDateFormat($dateString) ) {
			$dateArr = split('[-,/,.]', $dateString);
			if ($short == true) {
				return sprintf("%02d/%04d", $dateArr[1] , $dateArr[0]);
			} else {
				return sprintf("%02d/%02d/%04d", $dateArr[2] , $dateArr[1] , $dateArr[0]);
			}
		//} else {
		//	return $dateString;
		//}
	}

?>
line 3744 is this:

Code: Select all

return sprintf("%02d/%02d/%04d", $dateArr[2] , $dateArr[1] , $dateArr[0]);
i think that there's problem with dates, but I dont know where... or what is wrong

thanks for all ideas... thanks a lot...

Posted: Wed Nov 07, 2007 7:48 am
by CoderGoblin

Code: Select all

$dateArr = split('[-,/,.]', $dateString);
is not splitting the date as you expect, returning only 2 values instead of 3.

I would echo the $dateString and print_r($dateArr) to assist in debugging.

As a side note always use "<?php" rather than "<?" (<? relies on a php settting which is not always switched on if you ever switch servers)