RicardO
RicardO

Reputation: 1229

match date from string php preg_match

I have a string:

$string = "Created on: 06-Sep-08";

I would like to match the date and convert it to 06/09/2008; what is the needed regexp?
Thanks

Upvotes: 1

Views: 4354

Answers (2)

Ciprian Mocanu
Ciprian Mocanu

Reputation: 2196

preg_match('/\:.*/is',...);

And then do a

strtotime(...)

EDIT:

Forgot to add the parantheses

preg_match('/\:(.*)/is',$string,$matches);

Upvotes: 3

deiga
deiga

Reputation: 1637

$matches = array();
preg_match('/(\d{2})-(\D*)-(\d{2})/', $string, $matches)

This returns the array matches.

$matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on

http://php.net/manual/en/function.preg-match.php

Upvotes: 4

Related Questions