Forum Moderators: coopster
im new to php, and i've found a tutorial on some website i cant remember that tells you how to do the whole
<?
switch ($_GET['action'])
{
case 'news'
include('news.htm');
break;
default: include('welcome.htm');
break;
}
?>
thing, and this works fine with my site. the problem is, i've got hundreds of pages i want to include, and i'm adding more all the time, i dont want to have to keep adding another "case 'asdf' include('asdf.htm')" for every page.
what i really want, is for the php page to automatically include the html file with the same name as the variable in the URL, so for example if the url was
calendar.php?month=may2003
then the php page would automatically try and load may2003.htm in the same folder. (it would be better if it could load "/calendar/may2003.htm" but im not that worried if thats too complicated.
sorry if i havent explained it very well, i'm still a n00b hehe :)
// Define the path to your file
$pathToFile = "/dir/to/my/file/";
$fileToInclude = $pathToFile.$_GET['action'].".htm";
if(is_file($fileToInclude))
{
include($fileToInclude);
} else {
// file doesn't exist, include default
include($pathToFile."welcome.htm");
}
Now for your calendar.php, you'd do something similar, but replace $_GET['action'] by $_GET['month']
hope that helps
mavherick
[added]just noticed the default case[/added]