Solved

explode with dash not working - why?

Posted on 2009-07-06
3
569 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now