Solved

explode with dash not working - why?

Posted on 2009-07-06
3
595 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:alicia1234
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
kevin_u earned 125 total points
ID: 24789104
$datearrary = explode("-",$datetext);  // break

datearray is spelled wrong
0
 

Author Comment

by:alicia1234
ID: 24789117
Duh. ;-)
It's been a long day.
Thanks!
0
 
LVL 12

Expert Comment

by:kevin_u
ID: 24789132
we all have them.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Query return divisible by 3 3 26
Logic behind "best rated" calculation 11 30
PHP error function not working on AWS 10 67
jQuery Toggle & Anchor Links 5 43
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question