understanding problem!!!

A

Anonymous

Guest
hi
i cannot understand ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) in this scripte ,
can anyone guide me?
Code:
<?php
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
    echo "$regs[3].$regs[2].$regs[1]";
} else {
    echo "Invalid date format: $date";
}
?>
 
As far as I know

([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})
is a regular expression for checking date.


[0-9]{4} means accept 0 to 9 (only 4 digits). I think it is for Year.
Then - (only dash)
[0-9]{1,2} means accept 0 to 9 (1 or 2 digits). I think it is for month.
Then - (only dash)
[0-9]{1,2} means accept 0 to 9 (1 or 2 digits). I think it is for date.

So it will ereg will check that date is in the regx format or not.

It may accept dates like

2006-08-15
2006-8-15
2006-8-09
2006-8-9
etc.
 
Back
Top