| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
function check_day($day) { |
|---|
| 22 |
|
|---|
| 23 |
if ($day === '') return 0; |
|---|
| 24 |
if (preg_match("/^0?[1-9]$/D", $day)) return 1; |
|---|
| 25 |
if (preg_match("/^[1-9][0-9]$/D", $day) && (9 < $day) && ($day < 32)) return 1; |
|---|
| 26 |
|
|---|
| 27 |
return 0; |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
function check_month($month) { |
|---|
| 31 |
|
|---|
| 32 |
if ($month === '') return 0; |
|---|
| 33 |
if (preg_match("/^0?[1-9]$/D", $month)) return 1; |
|---|
| 34 |
if (preg_match("/^[1-9][0-9]$/D", $month) && (9 < $month) && ($month < 13)) return 1; |
|---|
| 35 |
|
|---|
| 36 |
return 0; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
function check_year($year) { |
|---|
| 40 |
|
|---|
| 41 |
$current_year = date("Y", time()); |
|---|
| 42 |
if ($year === '') return 0; |
|---|
| 43 |
if (preg_match("/^[1-9][0-9][0-9][0-9]$/D", $year) && (1899 < $year) && ($year < ($current_year + 1))) return 1; |
|---|
| 44 |
|
|---|
| 45 |
return 0; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
function check_date($date) { |
|---|
| 49 |
|
|---|
| 50 |
if ($date === '') return 0; |
|---|
| 51 |
$res = preg_match_all("/^([^\.]+)\.([^\.]+)\.([^\n]+)\n/D", "$date\n", $parts, PREG_PATTERN_ORDER); |
|---|
| 52 |
if ($res != 1) return 0; |
|---|
| 53 |
if (check_day($parts[1][0]) && check_month($parts[2][0]) && check_year($parts[3][0])) return 1; |
|---|
| 54 |
|
|---|
| 55 |
return 0; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
function split_date($date) { |
|---|
| 59 |
|
|---|
| 60 |
if (check_date($date)) { |
|---|
| 61 |
$res = preg_match_all("/^([^\.]+)\.([^\.]+)\.([^\n]+)\n/D", "$date\n", $parts, PREG_PATTERN_ORDER); |
|---|
| 62 |
return array($parts[1][0], $parts[2][0], $parts[3][0]); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
return ''; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
?> |
|---|