I prefer to use PHP’s require because if there is a problem an error is produced. Also while testing I prefer to use PHP’s die; because it immediately halts execution and displays any messages. Without the PHP die; and depending on the error configuration error messages are mostly likely to be hidden.
is what I suggested - not date(‘M’) and not adding may before the .php
date(‘F’) - will currently return ‘April’ then strtolower converts it to ‘april’ to which the concatenation makes it ‘april.php’. Tomorrow you’d get ‘may.php’;
strtolower(date(‘M’)).‘may.php’ - currently gives ‘aprmay.php’ and tomorrow it will give ‘maymay.php’
I apologise for supplying script which was not tested.
The problem was date('n'); returns a string and not an integer.
A quick solution, which I have tested is to force the string to be an integer:
Update:
$month = date('n'); // "4" == April, "5" = May, etc // string with no leading zero
switch( (int) $month ){
case 1 : include 'january.php'
break;
case 2 : include 'february.php'
break;
...
...
...
} // endswitch(...)
$month = date('n');
// $month = 13; // just testing to see if invalid motnh
switch( (int) $month ){
case 1 : include 'january.php'; // same directory
break;
case 2 : include '../february.php'; // parent directory
break;
case 3 : include '/march.php'; // root directory
break;
case 4 : include '/test/test-001/april.php';
break;
case 5 : include '/test/test-002/may.php';
break;
case 6 : include '/test/test-003/june.php';
break;
//...
//...
//...
default: include 'not-a-month-just-blurb.php';
} // endswitch(...)
Edi:
It is verbose but easy to read and also easy to adjust different paths. Also easy to setup test paths.
Most of the pages will have the same content. Bu depending on the month one of the include files I have needs to change content and also a page called ‘term-dates.php’ needs it content changing depending on the month.
So I was thinking of including directories such as /may, /feb etc that contain more or less the same content just with a few small changes.
The principle being that function, strtolower(date('F')) will give you the current date in lower case, so you just insert that wherever you need the month in a string/path or whatever.
Note that 'F' will be the full month name, as in January. If you want Jan, Feb etc, use 'M' instead.
the integrity of the server is more important than any development task. Don’t hand out server authentication details to random people on the Internet. I shouldn’t even have to say that.