php - Identify date-related text in a longer message -
i'm writing script extract dates message , convert them timestamps. php's strtotime (similar unix's date -c 'some date'
) perfect this, recognizes kinds of dates, such as:
- 5pm today
- 2010-11-15 16:30
- thursday 8:00
however, i'm having trouble finding dates in first place. example, in following string,
i'll there dinner tomorrow @ 9:00pm
i need isolate "tomorrow @ 9:00pm", that's part strtotime recognizes.
is there regular expression or similar return me dates can parsed strtotime?
the thing can think of date_parse. regular expression matches any format accepted strtotime
huge.
an example of date_parse:
$str = "i'll there dinner tomorrow @ 9:00pm"; $parsed = date_parse($str); print_r($parsed);
it output (i removed unimportant parts make result lighter):
array ( [year] => [month] => [day] => [hour] => 21 // 9:00pm [minute] => 0 // 9:00pm [second] => 0 // 9:00pm [fraction] => 0 [warning_count] => 1 [is_localtime] => 1 [zone_type] => 2 [zone] => -540 [is_dst] => [tz_abbr] => [relative] => array ( [year] => 0 [month] => 0 [day] => 1 // tomorrow (would -1 yesterday, etc.) [hour] => 0 [minute] => 0 [second] => 0 ) )
whether works depends on input looks like. if have more 1 instance of date in input string, not work expected.
Comments
Post a Comment