开发者

match date from string php preg_match

I ha开发者_JS百科ve 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


$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


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

And then do a

strtotime(...)

EDIT:

Forgot to add the parantheses

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜