I am working on some code to look at a text file of events and display all events which are current. However, I have a logical error, because a date that is a greater month then the current, less days than the current, and the same year does not display. I suspect the error is in the following if statement. Does anyone see where I messed up? Thanks for your help.
dates.txt
Code:
[COLOR=#000000][COLOR=#007700]if ( [/COLOR][COLOR=#0000bb]$lineDay [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000bb]date[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"d"[/COLOR][COLOR=#007700]) && [/COLOR][COLOR=#0000bb]$lineYear [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#dd0000]"20"[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]date[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"y"[/COLOR][COLOR=#007700]) && [/COLOR][COLOR=#0000bb]$lineNumberMonth [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]date[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"m"[/COLOR][COLOR=#007700]) )[/COLOR][/COLOR]
PHP:
<?php
$intMonth = date("m"); // number of month
$currentLine = 0; // line counter for file
$currentLineRead = 0;
$writeCurrentLineYN = FALSE;
$file = fopen("dates.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
$currentLineRead = fgets($file);
$writeCurrentLineYN = proccessLine( " ".$currentLineRead );
if ($writeCurrentLineYN == TRUE )
{
echo $currentLineRead."<br />";
$writeCurrentLineYN = FALSE;
} // end if
$currentLine++;
}
function proccessLine($currentLineProccessing)
{
$lineNumberMonth = getNumberMonth($currentLineProccessing); // get number month
$lineYear = getYear( $currentLineProccessing); // Determine The Year
$lineDay = getDay( $currentLineProccessing); // determin the day
if ( $lineYear >= "20".date("y") ) // check year
{
if ( $lineNumberMonth > date("m") && $lineYear == "20".date("y") ) // check month
{
return FALSE;
} // end if
else
{
if ( $lineDay < date("d") && $lineYear == "20".date("y") && $lineNumberMonth == date("m") )
{
return False;
} // end if
else
{
return TRUE;
} //end else
} // end else
} // end if
} // end function proccessLine
function getDay ($currentLine)
{
$year = getYear($currentLine);
$startOfYear = strpos( $currentLine, "$year"); // get string position of year
// get a substring which contains the day
$subSDay = substr("$currentLine", 1, $startOfYear-1);
$guessDay = 99;
while (strpos( $subSDay, "$guessDay") == 0)
{
$guessDay--;
} // end while
return $guessDay;
} // end function getDay
function getYear ($currentLine)
{
$guessYear = 2000;
while (strpos( $currentLine, "$guessYear") == 0)
{
$guessYear ++;
} // end while
return $guessYear;
} // end function getYear
function getNumberMonth ($currentLine)
{
// Determine Number Month
for ($currentLineMonth=1; $currentLineMonth<13; $currentLineMonth++)
{
if ( (strpos( $currentLine, thisMonth($currentLineMonth))) == 1)
{
return $currentLineMonth;
} // end if
} // end for
} // end function getNumberMonth
function thisMonth($currentMonth)
{
switch ($currentMonth)
{
case 1:
return "January";
break;
case 2:
return "February";
break;
case 3:
return "March";
break;
case 4:
return "April";
break;
case 5:
return "May";
break;
case 6:
return "June";
break;
case 7:
return "July";
break;
case 8:
return "August";
break;
case 9:
return "September";
break;
case 10:
return "November";
break;
case 11:
return "October";
break;
case 12:
return "December";
break;
} // end switch
} // end thisMonth
fclose($file);
?>
Code:
June 18, 2003 -- lksjdlkfjsdkljghwe
August 6, 2009 -- lksdjfklasfjdkljds
December 31, 2010 -- sdfjlskdafjlk
July 4, 2023 -- sdfasdfsdf
August 14, 2009 -- sadlkjflasd;j
December 3, 2009 -- sdalfjklkj
December 3, 2010 -- asdlkjfl
October 10, 2009 -- asdlfjlj