Forum Moderators: coopster
The pattern must be between 2004 and $currentYear, I want to return an error for any year out of that range, so I can't simply use [0-9]{4}.
Here is the code I'm using at the moment:
if ( preg_match("/2004¦2005¦2006¦all/i", $_GET['year']) ) {
$year = strip_tags($_GET['year']);
} else {
die("Please enter a year in the form of four digits between 2004 and $currentYear, or enter 'all' to see all years.");
}
Of course, there are a number of other ways to do this as well. One might be to create a range of years based on the current year and then check to see if the year is in that array:
if (in_array [php.net]($year, range [php.net](date [php.net]('Y') - 2, date('Y')))) {
if ($year >= 2004 && $year <= date('Y')) {