note 52739 added to function.strtotime
| From: | (releatgmxdotde) | Date: | Wed, 11 May 2005 12:48:51 +0000 |
| Subject: | note 52739 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89257@lists.php.net to get a copy of this message | ||
Here is a slightly improved version of date_uk_to_american, posted by James McGuigan on 27-Dec-2004
08:31.
Now you can use the function to parse a date string (user input) to show, whether it was recognized
correctly.
function date_uk_to_american($date, $replace_separator = FALSE) {
$days = '0?[1-9]|[12][0-9]|3[01]';
$months= '0?[1-9]|1[0-2]';
$year = '\d{2}|\d{4}';
$non_alpha = '[^0-9a-zA-Z]+';
return preg_replace( "/^\s*($days)($non_alpha)($months)($non_alpha)($year)/",
$replace_separator === FALSE ? '$3$2$1$4$5' :
'$3'.$replace_separator.'$1'.$replace_separator.'$5', $date);
}
function parse_date($date) {
return date("d.m.Y", strtotime(date_uk_to_american($date, '/')));
}
//example: echo parse_date('3.12.83');
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52739
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52739&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52739&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52739&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52739&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52739&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52739&report=yes
Search -- http://master.php.net/manage/user-notes.php