Writing correct code can sometimes be tricky, but in this case there is good help to find in the different validators. w3c has a nice html validator that can check your page for errors, you can find it at http://validator.w3.org/
Well since the basic pages did not validate you need to modify it a little, tell what type of html you use and what character encoding. So we just add those changes to the constructor.
Filename: class.page.php
<?php
class page
{
function __construct()
{
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
print "<html>\n";
print "<head>\n";
print " <title>My test page</title>\n";
print " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
print "</head>\n";
print "<body>\n";
}
function __destruct()
{
print "</body>\n";
print "</html>\n";
}
}
?>
Notice that the page that is calling don't need to be modified at all.
Filename: p05_ex01.php
<?php
require_once("class.page.php");
$page = new page();
?>
<h1>Hello</h1>
<p>What a nice little page</p>