i have $date
variable 2009-04-29
which is Y-m-d
anybody can give idea how to extract into $d
, $m
, $y
using simplest method as possible?
regex is preferable.
any more suggestion with simple method will be chosen. :)
i have $date
variable 2009-04-29
which is Y-m-d
anybody can give idea how to extract into $d
, $m
, $y
using simplest method as possible?
regex is preferable.
any more suggestion with simple method will be chosen. :)
Use explode
function
list ( $y, $m , $d ) = explode( '-' , $date ) ;
Refer following link for more information
You could easily avoid regex by using
$y = substr($date, 0,4);
$m = substr($date, 5,2);
$d = substr($date, -2);
Edit: If you really want regex, you will have one =)
Try
preg_match('/(\d{4})-(\d{2})-(\d{2})/', $date, $matches)
$y = $matches[1];
$m = $matches[2];
$d = $matches[3];
(I do not know if the backslashes in the expression need to be escaped, sorry)