I'm quite new to PHP and I've been asked to write a script that displays an image based on time. I've deducted that I need to use PHP's native 'date' function for this and up until I was asked to implement bank holidays and Christmas into it, all went well.
I tried to add the Christmas and bank holidays in as a separate if statement but that was when disaster struck and I haven't been able to figure out why it's come to a halt. I've tried using an online PHP validator to no avail.
Please don't be afraid to throw details and jargon at me as I really wish to expand my knowledge of PHP and rely less on the support of web forums in the future!
Here is the code:
<?php
// Date-time (day of month, month)
$d = date('j'); // Day of month: Numeric without leading zeroes
$m = date('n'); // Month: As above
$D = date('w'); // Day of week
$H = date('G'); // Hour of day
// REGULAR OPENING TIMES
// Closed before 9am on weekdays
if ($H < 9 && $D <= 5) :
$showroom_img = '/media/gbu0/pagehead/showroom_closed.jpg';
// Open before 5pm (but after 9, as first if statement overrides this) on weekdays
elseif ($H < 17 && $D <= 5) :
$showroom_img = = '/media/gbu0/pagehead/showroom_open.jpg';
// Closed before 10am on Saturdays
elseif ($H < 10 && $D == 6) :
$showroom_img = = '/media/gbu0/pagehead/showroom_closed.jpg';
// Open between 10am and 2pm on Saturdays
elseif ($H < 14 && $H > 10 && $D == 6) :
$showroom_img = = '/media/gbu0/pagehead/showroom_open.jpg';
// Any other time, display closed image :)
else :
$showroom_img = = '/media/gbu0/pagehead/showroom_closed.jpg';
endif;
// Holidays 2014
$xmas_starts = ($d == 23 && $m == 12 && $d > 17);
$xmas_ends = ($d == 26 && $m == 12);
$nyd = ($d == 1 && $m = 1);
// Easter Friday: April 18
// Easter Monday: April 21
// Early Spring B/H: May 5
// Late Spring B/H: May 26
// Summer B/H: August 25
// All bank holidays: 10am - 2pm
if( date >= $xmas_starts && $day <= $xmas_ends ) :
$xmas = true;
elseif( date = $nyd ) :
$nyd = true;
else :
$bankhol = false;
endif;
if( $xmas = true ) :
$showroom_img = "/media/gbu0/pagehead/showroom_xmas.jpg";
elseif( $bankhol = true && date('F', 'j') = strpos('April 18' || 'April 21' || 'May 5' || 'May 26' || 'August 25') || date('w') = 6 ) :
$showroom_img = "/media/gbu0/pagehead/showroom_bhol.jpg";
elseif( date('w') = 7 ) :
$showroom_img = "/media/gbu0/pagehead/showroom_closed.jpg";
else :
$showroom_img = "/media/gbu0/pagehead/showroom_open.jpg";
endif;
?>