Jump to content

bgareth

Members
  • Posts

    14
  • Joined

  • Last visited

bgareth's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Barand, how am I doing, I've probably got this totally wrong: [code] <?php function EnglishHols($year) { $englishHolidays = array(); $t = mktime(0,0,0,1,1,$year); $d = date('Y-m-d', $t); $englishHolidays[$d] = 'New Year\'s Day'; /* Ben's Note - Get Unix timestamp (number of seconds since 1970) for 1 January of the current year and then append the $year variable to it (defined later) to the $t variable) then find the date and assign this to $d variable appended by the $t variable. The last line I don't get, I don't know what square brackets do..*/ $t = easter_date($year); $d = date('Y-m-d', strtotime('-2 days', $t)); $englishHolidays[$d] = 'Good Friday'; $d = date('Y-m-d', $t); $englishHolidays[$d] = 'Easter Sunday'; $d = date('Y-m-d', strtotime('+1 days', $t)); $englishHolidays[$d] = 'Easter Monday'; /* Ben's Note - Reassign $t variable to now carry easter_date function and append the year variable (yet to be assigned). Reassign $d variable to contain date function and then convert it to unix timestamp as defined above but this time taking a normal date to do it (so different function name.) Take two days off the unix timestamp and append the $t variable to the end. Now assign the variable $englishHolidays to contain unix timestamp calculated in $d variable (why specified i.e. $englishHolidays[$d]?) and assign that to the text 'Good Friday'. Reassign $d variable again to contain date function converted to unix timestamp and add 1 day to the timestamp returned. Append the $t variable to the end (is $t variable inherited from above or from below?) Reassign variable $englishHolidays to contain newly assigned $d variable and add the string 'Easter Sunday'. (This does not have any days added or subtracted and doesn't seem to refer to the function easter_date? How does this bit work? Reassign $d variable yet again and convert it to unix timestamp adding 1 day and append $t variable to the end. Reassign variable $englishHolidays to contain $d variable and append the string 'Easter Monday'.*/ Please give me some feedback :-) Kind Regards, BG.
  2. Sen, thanks, hopefully me disecting your code didn't offend you? I'm a newbie so It just helped to be able to read it to myself in English using your explanation :-) Thanks again, will re-read :-)
  3. Hello Jessica :-) Which one do you think is harder? Sen, Thanks for this - 1. You have declared the variable $year without content? Can you declare the content later? function EnglishHols($year) 2. What is going on with the $t variable here? It seems that it is being reassigned in the following section? $t = easter_date($year); $d = date('Y-m-d', strtotime('-2 days', $t)); $englishHolidays[$d] = 'Good Friday'; $d = date('Y-m-d', $t); $englishHolidays[$d] = 'Easter Sunday'; $d = date('Y-m-d', strtotime('+1 days', $t)); $englishHolidays[$d] = 'Easter Monday'; 3. you have used the mktime function, what is the difference between that and the way I have specified dates and times so far and what is each properly used for? Thanks and Kind Regards, BG.
  4. Hello Jessica, thanks for your message, can it be done the way I have posted above or would it have to be done the way you have suggested? Thanks for taking the time to add to this :-) Kind Regards, BG.
  5. Hello, i've shortened the echo statement as suggested above and it works! Moving forward with the multidimensional array, so far this is what i've done: /* Multidimensional array for holidays - Christmas will be added later.*/ $holidays = array( array("Boxing_Day", 2612), array("Easter_Monday", 0104), array("Good_Friday", 2903), array("January_2nd", 0201), array("May_Day_Holiday", 0605), array("New_Year's_Day", 0101), array("New_Year's_Eve", 3112), array("Orangeman's_Day", 1207), array("Saint_Patrick's_Day", 1703), array("Spring_Bank_Holiday", 2705), array("St_Andrew's_Day", 3011), array("Summer_Bank_Holiday_Scotland", 0508), array("Summer_Bank_Holiday_ENIW", 2608), ); For example, Summer_Bank_Holiday_Scotland has a value of 0508 which is the 5th August. Is this correct so far and if so how do I write the loop that Muddy_funster is proposing above? Thanks again :-)
  6. That's very kind :-) Is there an "idiot's guide" to multi-dimensional arrays and what does it mean in English if you were to put the term in laymen's terms :-) I'm inspired by setting myself goals to do things that I know i'll use, i'm setting myself tasks as I read the SAMS Teach Yourself book I have :-) I'm no good with the "official" reference materials on php.net - at this stage a lot of it is gobbledygook on that site!
  7. With respect to adding in the extra holidays, is an array appropriate or an if statement or even another method you can suggest? I'm looking at adding in things like St Patrick's Day, Bonfire Night etc. Thanks to Muddy_Funster, also to you Beeeeeney, what you have both said so far makes sense.
  8. Thanks, I don't know how long you have been coding but if you remember back to when you started, it is hard enough to make your code run without errors :-) I appreciate your help so far and your a decent enough guy to post back. You see all those echo statements (19 of them), there must be a way of shortening them? I had already looked at the link you suggested but i'm not sure how I can join them up (presumably this is what you are referring to when you say you can have more than one parameter inside the date() function)? Edit - ah I didn't see this bit: // Prints something like: Monday 8th of August 2005 03:12:46 PM echo date('l jS \of F Y h:i:s A'); Is that an example of what you are suggesting, I notice the /of Is that how to incorporate bits of text in lines of PHP? I didn't realise escape could be used for anything other than apostrophes and double quotes..
  9. Well people have to start somewhere and that is quite discouraging. I'm trying to learn. Considering I only really started trying to learn a couple of days ago, surely I have done quite well to get this far, particularly as, save for some basic CSS and HTML, I have not coded before. When I used the word "professional" I meant efficient and I was essentially asking if it was written in the same way as anyone with a good rounded knowledge of PHP would write it. I have advanced the script slightly and I would like to add in some other holidays. I also feel that my echo format for the current time and date is way too long, there must be a way to shorten it. Further, to add in the extra holidays is it more appropriate to use an array, to write an if statement for each one or is there another way? Regards, BG. <!DOCTYPE html> <html lang="en"> <head> <title>English Holiday Checker</title> <!-- Inline CSS (in case you were wondering!) --> <style> /* Collaborative Header CSS */ h1 {text-align:center; color:black; font-family:"Arial", Calibri, "sans-serif";} /* Collaborative Paragraph CSS */ p {margin-left: 20px; font-family:"Arial", "Calibri", "sans-serif"; color:blue;} </style> </head> <body> <!-- Header for page --> <h1>English Holiday Checker</h1> <p> <?php /* Variable declarations */ $weekday = date("D"); $od = date("S"); $day = date("d"); $month = date("M"); $year = date("Y"); $hour = date("H"); $minute = date("i"); $seconds = date("s"); /* Display current time and date */ echo "<p>The time when you loaded this page was: "; echo $hour; echo ":"; echo $minute; echo ":"; echo $seconds; echo " GMT"; echo " and the date was "; echo $weekday; echo ", "; echo $day; echo $od; echo " "; echo $month; echo " "; echo $year; echo "."; echo "</p>"; echo "<p>I haven't learnt Javascript yet so I can't set it to auto-update without using meta-refresh.</p>"; /* To determine whether it is Christmas Eve the following day and if so to display a message after 7pm on 23 December. */ if ($day == 23 and $month == 12 and $hour > 19) { echo "<p>Christmas Eve is tomorrow.</p>"; } /* To determine whether it is Christmas Day the following day and if so to display a message after 7pm on 24 December. */ elseif ($day == 24 and $month == 12 and $hour > 19) { echo "<p>Christmas Day is tomorrow.</p>"; } /* Message to display if it is neither Christmas Eve or Christmas Day the following day. */ else { echo "<p>We are not in the Christmas period.</p>"; } ?> </p> </body> </html>
  10. So delete the assignment of the variable to date function and simply set the variable to "23" "12" "1900" respectively? Is that the format of the time variable stored? Is my code rubbish and are there any improvements to make it more professional? Thanks for your help :-)
  11. Is it deff working properly, not sure how to make it trigger the christmas messages when it isn't christmas to test it...
  12. Wow Beeeney it's working, you share my nickname in real life btw! See i'm learning quick :-p
  13. Hello, Please could you give me a bit of guidance on the following script, half of it is appearing (as code) in my browser on my Wamp installation! <html> <head> <title>PHP Christmas Message Challenge</title> </head> <body> <?php /*Array assignment*/ $day = date("d"); $month = date("m"); $hour = date("H"); /* To determine whether it is Christmas Eve the following day and if so to display a message after 7pm on 23 December. */ if ($day == 23 and $month == 12 and $hour > 19) { echo "Christmas Eve is tomorrow."; } /* To determine whether it is Christmas Day the following day and if so to display a message after 7pm on 24 December. */ elseif ($day == 24 and $month == 12 and $hour > 19) { echo "Christmas Day is tomorrow."; } /* Message to display if it is neither Christmas Eve or Christmas Day the following day. */ else { echo "Tomorrow is a normal day."; } ?> </body> </html> Kind Regards, BG.
  14. Hello, I can't achieve what I am looking to do here: <html> <head> <title>PHP Weekend Challenge</title> </head> <body> <?php \\*if month = december and day = 23rd and time=19:00-23:59 echo "Good Evening, tomorrow is Christmas Eve!" or if month = december and day = 24th and time=19:00-23:59 echo "Good Evening, tomorrow is Christmas Day!" else echo "It's not Christmas so too bad - it's just another 7 day working week!"*\\ ?> </body> </html> I'm a newbie so please assume I know nothing about PHP and provide as much explanation as you can for the solutions you give. I have read around on different websites and I find it exceptionally difficult to understand them because of my dyslexia and dyscalculia. Please advise :-) Thanks and Kind Regards, Beanie
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.