date pattern

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

date pattern

Post by m2babaey »

Hi
I have read some tutorials for regular expressions but I'm still unable to detect date patterns
for example I have a string like:

Code: Select all

$string="<updated>2010-04-19T05:17:00+00:00</updated>";
I need to capture "2010-04-19T05:17:00+00:00" in $match[] using preg_match where <updated> </updated> is presented
How can I achieve that?
Thanks for your help
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: date pattern

Post by requinix »

Are you using any kind of XML parsing library, or do you only have that string and nothing else?
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Re: date pattern

Post by m2babaey »

$string is actually the result of get_file_content and is longer than above
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: date pattern

Post by requinix »

Then without some easier method,

Code: Select all

preg_match('#<updated>([\dT:+-]+)</updated>#', $string, $matches)
$matches[1] is the date. You can use strtotime to get a timestamp - for use with date() and whatnot.
Post Reply