I am trying to create a template page (masterPage.php) where a header.php and footer.php files are included on the page, and and body (index.php, about.php, etc) are used for the body content of each page. I have this somewhat working but for some reason the content portion is showing up before the header and footer. Is there a better way to do this? -- Thanks
masterPage.php
header.php
footer.php
index.php
masterPage.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Site</title>
<!-- You can include any additional CSS or meta tags here
<link rel="stylesheet" href="styles.css"> -->
</head>
<body>
<table border="1px" width="100%">
<tr>
<td>
<?php
require_once('header.php');
?>
</td>
</tr>
<tr>
<td>
<?php
$content
?>
</td>
</tr>
<tr>
<td>
<?php
require_once('footer.php');
?>
</td>
</tr>
</table>
</body>
</html>
header.php
<table border="1px" width="100%">
<tr>
<td>Header</td>
</tr>
</table>
footer.php
<table border="1px" width="100%">
<tr>
<td>Footer</td>
</tr>
</table>
index.php
<?php
function pageContent()
{
print("<table border='0px' width='100%'>");
print("<tr>");
print("<td>Index</td>");
print("</tr>");
print("</table>");
}
$content = pageContent();
require_once('masterPage.php');
?>