0

I have an issue with PHP files displaying information site. I'm working on a localhost and my .htaccess file is correctly configured to display .php files, as a .php file works on an html file.

But, when I tried to make a switch variable to switch between different pages dependent on a date...

<?php
switch(date('l')) {
   case 'Sunday': $page = 'sunday.html'; break;
   case 'Monday': $page = 'monday.html'; break;
   case 'Tuesday': $page = 'tuesday.html'; break;
   case 'Wednesday': $page = 'wednesday.html'; break;
   case 'Thursday': $page = 'thursday.html'; break;
   case 'Friday': $page = 'friday.html'; break;
   case 'Saturday': $page = 'saturday.html'; break;
}
echo file_get_contents($page);
?>

..then the php include code inside the .html would not work. Same with php echo, it would not display. Where might I be going wrong? My index.html (where onair.php works and is displayed on index.html) links to /programmes/schedule.html which then links to a respective page on a given day. There, the PHP code that is the same as in index.html does not display... It is simply commented in Google Chrome.

Any help would be appreciated. Cheers.

2
  • What is date('l')? Try echoing just try value. Commented Jan 21, 2012 at 14:44
  • Complicate much? include strtolower(date('l')) . '.html'; Commented Jan 21, 2012 at 14:52

3 Answers 3

2

You need to include the pages instead. Neither file_get_contents nor echo will execute PHP script.

<?php
switch(date('l')) {
   case 'Sunday': $page = 'sunday.html'; break;
   case 'Monday': $page = 'monday.html'; break;
   case 'Tuesday': $page = 'tuesday.html'; break;
   case 'Wednesday': $page = 'wednesday.html'; break;
   case 'Thursday': $page = 'thursday.html'; break;
   case 'Friday': $page = 'friday.html'; break;
   case 'Saturday': $page = 'saturday.html'; break;
}

include $page;
?>

Of course, you can make it simpler, too:

<?php
include strtolower(date('l')) . '.html';
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Is that what his question is? I could tell.
@AshBurlaczenko: I took an educated guess :) ".then the php include code inside the .html would not work." and "It is simply commented in Google Chrome."
1

PHP cannot be executed within HTML files unless you use eval(). You can either rename your files to .php rather than .html (better choice in my opinion), or set HTML to be run as PHP file by adding the following to your .htaccess:

AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm

Comments

0

The path might not be the same, check using a code like this:

readfile(realpath(dirname(__FILE__).DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$page);

or include if you want to be interpreted.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.