How to split/get a date of known format from a string in php (pregmatch)
I've got a string, which contains a date with time and i wa开发者_如何学JAVAnt to convert it to the unix format or something like that, so that i can save it into the database..
It looks always in this form "Mittwoch, 03. August 2011, 09:00 Uhr"
I don't want to write it with string functions but with pregmatch, which i can't use true yet..
The PHP DateTime class has a method called DateTime::createFromFormat()
that should be able to parse the date you have. You can then call $datetime->format('U');
to get the Unix Timestamp version.
It will only work with PHP > 5.3 however.
preg_match('/\w*,\s+(\d{2})\.\s+(\w*)\s+(\d{4}),\s+,(\d{2}):(\d{2})/', $inputString, $matches)
$matches[1] = day of month
$matches[2] = Month
$matches[3] = Year
$matches[4] = Hour
$matches[5] = Minute
You can then use mktime/time to convert it.
精彩评论