newformula Posted September 8, 2009 Share Posted September 8, 2009 My first time on the phpfreaks forum, and thanks in advance for any help I might get here. A buddy of mine wrote some code for me a while back - my PHP is rusty (you could say it was never shiny), and I'm struggling to understand what's going on so I can enhance it. This code powers http://nextmanlyferry.com. The whole code suite is available in google code - http://code.google.com/p/php-timetable-app/ In a nutshell, the function reads through a text file (name based on the current day of the week) which contains a series of times (events) on new lines e.g. 1930, 2000, 2030 etc. The current time is compared with the event times in the file, and outputs 3 variables - $inboundprevEventTime, $inboundEventTime and $inboundnextEventTime. The first is the event time that's just passed, the next the event time that is next, and the last the event time that is next + 1. There's also some checks to read into the next and previous day's times if it's the tail end of beginning of the day. I set up some config variables such as hour offset from UTC in config.php, and some time variables such as $date in timevariables.php. I want to enhance this to allow me to output the event times coming within the next hour (preferred) or the next four events. I'd imagine you might need to ask some more questions to help... but I'd be really grateful if someone could help me on this one. Thanks in advance.... <?php require("config.php"); inboundeventTime($hoursfromUTC,$inboundprevEventTime,$inboundEventTime,$inboundnextEventTime); function inboundeventTime($offset,&$inboundprevEventTime,&$inboundEventTime,&$inboundnextEventTime) { $inboundEventTime=$inboundprevEventTime=$inboundnextEventTime=0; $txtFolder="inboundtimes/"; require("timevariables.php"); //read today $lines=array_map("trim",file($txtFolder."{$date}.txt")); sort($lines); if(!$lines)return; //read tomorrow $linesNext=array_map("trim",file($txtFolder."{$dateNext}.txt")); sort($linesNext); if(!$linesNext)return 0; //read yesterday $linesPrev=array_map("trim",file($txtFolder."{$datePrev}.txt")); sort($linesPrev); if(!$linesPrev)return 0; for($i=0;$i<count($lines);$i++) { if($lines[$i]>$time) { //first event for day if($i==0) $inboundprevEventTime=$linesPrev[count($linesPrev)-1]; //take from prev day else $inboundprevEventTime=$lines[$i-1]; $inboundEventTime=$lines[$i]; //last event for day if($i== (count($lines)-1) ) $inboundnextEventTime=$linesNext[0]; //take from next day else $inboundnextEventTime=$lines[$i+1]; return; } } //default first event from nextday $inboundprevEventTime=$lines[count($lines)-1]; $inboundEventTime=$linesNext[0]; $inboundnextEventTime=$linesNext[1]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173476-i-dont-understand-my-own-function-that-i-wrote-a-while-back/ Share on other sites More sharing options...
RussellReal Posted September 8, 2009 Share Posted September 8, 2009 this will probably be moved to phpfreelance.. not being rude or anything but it seems like more of a request than solving an error or two lol Quote Link to comment https://forums.phpfreaks.com/topic/173476-i-dont-understand-my-own-function-that-i-wrote-a-while-back/#findComment-914485 Share on other sites More sharing options...
newformula Posted September 8, 2009 Author Share Posted September 8, 2009 Thanks - no offence taken. If it needs moving, someone please do so : ) Quote Link to comment https://forums.phpfreaks.com/topic/173476-i-dont-understand-my-own-function-that-i-wrote-a-while-back/#findComment-914500 Share on other sites More sharing options...
bundyxc Posted September 8, 2009 Share Posted September 8, 2009 So you have a bunch of files, like monday.txt, tuesday.txt, etc? I think this would be easier to do with either one text file, or with a database. Are either of those an option? Quote Link to comment https://forums.phpfreaks.com/topic/173476-i-dont-understand-my-own-function-that-i-wrote-a-while-back/#findComment-914523 Share on other sites More sharing options...
newformula Posted September 8, 2009 Author Share Posted September 8, 2009 Hey bundy - that's correct. The times are in a Monday.txt file for example. I set it up in that way for ease of managing the times without having to manage a database. Everything is stored (and there's not much to store) in flat files for that reason. It also allows the lay-person to update the timings without knowledge of a database, setting up admin screens, etc. Not sure how I would move all times into one file and be able to read them out differently for different days? E.g. saturday times are different to weekday times. Quote Link to comment https://forums.phpfreaks.com/topic/173476-i-dont-understand-my-own-function-that-i-wrote-a-while-back/#findComment-914524 Share on other sites More sharing options...
bundyxc Posted September 8, 2009 Share Posted September 8, 2009 Well, your file could look this this: [MON/1830/Event1] [MON/0700/Event2] [TUE/1200/Event3] [WED/0000/Event4] [THU/2234/Event5] [FRI/1100/Event6] [sAT/0333/Event7] [sUN/0001/Event8] [FRI/2359/Event9] [WED/2359/Event10] [sUN/2359/Event11] Quote Link to comment https://forums.phpfreaks.com/topic/173476-i-dont-understand-my-own-function-that-i-wrote-a-while-back/#findComment-914528 Share on other sites More sharing options...
newformula Posted September 8, 2009 Author Share Posted September 8, 2009 OK - but I'm not seeing how that helps my current issue? Ideally I would like to setup another couple of variables:- $inboundEventTime=$lines[$i]; //this already exists $inboundnextEventTime=$lines[$i+1]; //this also already exists and works $inboundEventTime3=$lines[$i+2]; // these next two are new $inboundEventTime4=$lines[$i+3]; But whatever way I try and set those up I can't get those two new variables to return anything. Quote Link to comment https://forums.phpfreaks.com/topic/173476-i-dont-understand-my-own-function-that-i-wrote-a-while-back/#findComment-914529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.