Click to See Complete Forum and Search --> : Spliting a string into multiple strings


lightnb
03-24-2007, 07:49 AM
There's probly some simple function that does this, but I'm not sure what it's name is.

I have a variable called $date with a string in the format "dd/mm/yyyy".

I would like to make it into three strings/variables $day, $month, and $year.

something like:



split_function($day, $month, $year; / ; $date)



Can this be done? Or does it need to use three different string extract functions?

Thanks.

aj_nsc
03-24-2007, 09:15 AM
I'd use explode, but everyone has their own preference. Check php.com for functions for splitting strings, this is how I'd do it:


$string = "30/07/1985" //my birthday ;)
$date = explode("/",$string);
$day = $date[0];
$month = $date[1];
$year = date[2];

bokeh
03-24-2007, 09:25 AM
Or without creating a pointless intermediate variable:list($day,$month,$year) = explode("/",$string);