I'd like to do my HTML markup with PHP using require is this possible and if so how'd you do it?
Right now this is the code in my index.php:
<?php
require('header.php')
require('body.php')
htmlHead();
htmlContent();
?>
Then In my header.php file i've got this:
<?php
function htmlHead(){
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Hello World</title>
<link rel="stylesheet" href="/style.css" type="text/css">
</head>';
}
?>
and then for my body tags:
<?php
function htmlContent(){
echo' <body>
<div id="wrapper">
<p>Hello World!</p>
</div>
</body>
</html>
';
}
?>
Thanks in advance!
You don't need to put your HTML in functions. You can simply do something like:
require('my_header.php');
And the contents of my_header.php look like:
<html>
<head>
<title>My Title</title>
<link rel="stylesheet" href="<?php $someVariable; ?>" type="text/css" />
...
</head>
Easy peasy.