Needing urgent help with XML parser

Hi guys

OUR XML parser only shows three future events from an XML feed, however it needs to show future events starting TODAY as not tomorrow. Our PHP guy is out and I need to get this altered ASAP, can anyone help alter this code?


<?php
	$testfn = 'http://website.com';

   function prepareXML($url)
	{
		//function to encode and replace certain things that will make an XML file not well formed ie '&' => '&amp;'
		$str = utf8_encode(str_replace('&', '&amp;', file_get_contents($url)));
		/*$str = '<?xml version="1.0" encoding="UTF-8"?>' . $str;	*/

		return $str;
	}

	function loadXML($tempstr) 
	{
		$xmlobject = simplexml_load_string($tempstr);

		return $xmlobject;
	}
	
	function getNextEvents($object, $numtofetch = 3)
	{
		//function to recurse through object to find the next x number of events in the future. alter passed value of $numtofetch to change the date range of events.
		if (!is_int($numtofetch))
		{
			$numtofetch = 3;
		}
		
		$found = array();
		$currentdate = time(); 

		foreach($object->Events->Event as $event)
		{
			$eventtime = strtotime((string) $event->EventStartDateTime);
			if ($eventtime >= $currentdate)   !!!!!! not returning a result if event is today !!!!!!
			{
				array_push($found, $event);
			}
		}

		$found = array_reverse($found);
		//found now contains all matching events in reverse date order ie next in line to most distant in future
		//trim the array to first 3 and return
		return array_slice($found, 0, $numtofetch);
	}

	//call function to prepare XML string for passing to SIMPLE XML
	$xmlstr = prepareXML($testfn);

	//call function to load XML using string produced
	$xmlObj = loadXML($xmlstr);
	
	//call to find events in categories...
	$events = getNextEvents($xmlObj);

?>


Hi
Try replace

$eventtime = strtotime((string) $event->EventStartDateTime);

With:

$eventtime = strtotime($event->EventStartDateTime);

And test with

echo $eventtime. ' >= '. $currentdate;

to see what values those data have, maybe there are not selected the rows with timestamp from today, or there is a difference between the date-time of data registered in XML, and servers local time. In this case, a solution can be to decrease the value of $currentdate with one day:

$currentdate = strtotime("-1 day");        // or: strtotime("yesterday");

OR…


        $currentdate = time(); 

becomes


        $currentdate = strtotime('today');

(today returns the time as 00:00:00 on this date.)

Thanks for your quick replies guys! That should sort it.