Regular Expression, searching for a 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
User avatar
Templeton Peck
Forum Commoner
Posts: 45
Joined: Sun May 11, 2003 7:51 pm

Regular Expression, searching for a date

Post by Templeton Peck »

$test= eregi('April[12-20]2003',$date);


if $date is a date in this format: May 12 2003

how can I specify a range of dates like April [12-20] 2003 to match with it? I can't figure out how to get the spaces in, because right now its trying to match April122003 for example against the $date. I don't even know if i'm doing the range of numbers right.

Any assistance would be appreciated
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

>= 12 || <= 30

greater than or equal to 12 and less than or equal to 30
User avatar
Templeton Peck
Forum Commoner
Posts: 45
Joined: Sun May 11, 2003 7:51 pm

Post by Templeton Peck »

what about the spaces? how do I use it in an search expression

$test= eregi('April[12-20]2003',$date);

is what I have currently
User avatar
Templeton Peck
Forum Commoner
Posts: 45
Joined: Sun May 11, 2003 7:51 pm

Post by Templeton Peck »

To be entirely accurate what i'm trying to do is match a date which is in a variable called $date and is in this format : March 12 2003 (no comma's or anything just spaces)

a bunch of dates are passed to $date from a file and I want to know how to search a range of dates to match those dates

like March[12-20] 2003 is a range I could search against the dates from file and get a match for the one example date I gave above.

eregi('April+[11-21]+2003','$date'; is what I have but it doesn't work with or without plus signs, so how can I search the range April[11-23]2003 against the $date variable and get a match if April 11 2003 was the date in the $date file

thanks :)
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

try ereg and test $reg if it is in the range yoou wnat.


see php.net for the function.


as far as i know you can't to this directly within the expression, as you can only determin the kind of values not the range in the regexp



also see:
http://www.phpbuilder.com/columns/dario19990616.php3
Post Reply