What I have:
a string that says “Tue Aug 7, 2012 to Tue Aug 28, 2012”
What I want:
a string that says “Aug 7 – Aug 28”
The only catch is sometimes I have this as a string:
“Fri Aug 31, 2012 7:30pm to 9:30pm”
and I would need this as a result:
“Aug 31”
This is info that is coming from a Google calendar feed, so the incoming string is different based on whether user has put in start time, etc. Thanks for any help!
You can use the
preg_match_allfunction to make the logic easier:DEMO (change $str1 to $str2 in
preg_match_allto test case 2)This will work whenever there are one or more dates with the format
MON DorMON DDin your string. It doesn’t matter how the rest of the string is formatted, only that the month and day exist.