I have this kind of HTML structure (stripped down for easy readability):
<head>
<title>My website!</title>
<?php include "myFile.php"; ?>
</head>
...
<div id="header"></div>
<div id="content">
<?php GetSomeStuff(); ?>
</div>
<div id="footer"></div>
And then I have the myFile.php:
<?php
ob_start();
function GetSomeStuff()
{
if(something)
{
ob_end_clean();
?>
<p>some html here!</p>
<?php
ob_start();
}
}
ob_end_clean();
?>
We expect that our HTML will now look like:
<div id="header"></div>
<div id="content">
<p>some html here!</p>
</div>
<div id="footer"></div>
Well, guess what. This is what it looks like:
<p>some html here!</p>
<div id="footer"></div>
Not only does it insert the p tag at the beginning of the body tag, but it also removes my beautiful header and content divs! Also, my header tag is empty – no title! 🙁
Obviously I am doing something wrong. How can I do this correctly? Please note that the output is gonna be a tad bigger than what I posted here. 😉
Your myFile.php should be as follows: