Use templating, or even simpler (as a temporary solution) store each version of the page as a separate file in a subfolder, depending on one of the 4 options you can include the page by reading the file and printing it out. The point we're trying to make is, if you've got hundreds of lines of
pre-written HTML, it's easier to output it as HTML rather than PHP, because PHP allows this. You can jump in and out of PHP as you choose. For instance:
- Code: Select all
<?
if ($option1) {
?>
<html>
<head>
<title>You picked option 1</title>
</head>
<body>
This is the body for option 1
</body>
</html>
<?
} else {
?>
<html>
<head>
<title>You picked something other than option 1</title>
</head>
<body>
This is the body for whatever you picked
</body>
</html>
<?
}
?>
Try experimenting and see which works best for you. Don't forget that it has to be easily maintainable for you as well, so if they're large files, you might want to store them in 4 sub-files and include them when needed!
It's also worth remembering that PHP parses a PHP file
EVERY time before it executes (although there is a facility so it does it once, which speeds up your pages by a factor of 10), so if it's managing large files which contain 75% useless stuff (as the user will only get one result of 4) it's taking up processor time for no reason.
BTW, if you really want HTML written up as PHP, just do this:
- Code: Select all
<?
$oldFile = file("thefile.html");
while(list($lineNo,$line) = each($oldFile)) {
$newFile[] = "print '".str_replace(array("\\","'"),array("\\\\","\\'"),$line)."';";
}
$newFile = implode("\n",$newFile);
?>