Ok, so I have a string $title_string which could look like any of the following:
$title_string = "20.08.12 First Test Event";
$title_string = "First Test event 20/08/12";
$title_string = "First Test 20.08.2012 Event";
I need to end up with two variables:
$title = "First Test Event";
$date = "20.08.12";
The formatting for the date should be converted to full-stops, regardless of what it was originally.
The Regex string that I started with looks something like this:
$regex = ".*(\d+\.\d+.\d+).*";
But I can’t get this to work in the way I need it to. So all in all, I need to locate a date in a string, remove it from the string and format it correctly. Cheers.
Matching dates with regular expressions can be quite complex. See this question for an example regex. Once you’ve found the date, you can remove it from the title using str_replace().
Here’s a basic implementation:
Output: