Search text for date?

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
tetuanrp
Forum Newbie
Posts: 9
Joined: Fri Aug 12, 2005 1:20 pm

Search text for date?

Post by tetuanrp »

So here's what I got. I'm parsing a data feed, which consists of a block of text. In this text, sometimes there is one date (the text is descriptive text about an online coupon, and the date is the expiration date for the coupon). I want to search through this text, and check to see if there's a date within it, and if so, I want to pull it out into a variable. How can I search the text field and pull out a date?

The dates are coming through in two ways:
m-d-y
and
m/d/y

Any other dates that actually come as text, I'm assuming I won't be able to capture those, but that's only a limited amount anyway (ie. January 25, 2008)

The only idea I had was to maybe break the text up into an array (using a space as the seperator), then running through each array item checking if it's a date? Any ideas?

Thanks in advance!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

use a regular expression to search for a date format in your string.
tetuanrp
Forum Newbie
Posts: 9
Joined: Fri Aug 12, 2005 1:20 pm

Post by tetuanrp »

Yeah, regular expressions frighten me. I've researched em before, but need to study up on them again. Any good reference?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Post Reply