explode with dash not working - why?

alicia1234
alicia1234 used Ask the Experts™
on
I've attached the entire code snippet, include my debug echos ;-)

If $datetext is: 6/2/2009, the code works as expected.

If $datetext is: 6-2-2009, it doesn't. In the "assume dash is the delimiter" section of the code, $datearray is empty! I can't for the life of me figure out why!
if (!strpos($datetext, '/')) {
			// assume dash is the delimiter because no slashes found
			echo 'Dashes <br />';
			echo 'Date text is: ' . $datetext . '<br />';
			$datearrary = explode("-",$datetext);  // break into pieces: month, day, year
			echo 'datearray <br />';
			print_r($datearray);
			echo '<br />';
		} else {
			// assume / is the delimiter
			echo 'Slashes <br />';
			$datearray = explode("/",$datetext); // break into pieces: month, day, year
			echo 'datearray <br />';
			print_r($datearray);
			echo '<br />';
		}
		//if it wasn't a valid date string syntactically, or it was syntactically ok but an
		//invalid date (like 12/34/2009) this will catch it.
		return (checkdate($datearray[0],$datearray[1],$datearray[2])); //true or false

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
$datearrary = explode("-",$datetext);  // break

datearray is spelled wrong

Author

Commented:
Duh. ;-)
It's been a long day.
Thanks!

Commented:
we all have them.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial