Hi.
I keep getting a "Parse error: parse error, unexpected T_VARIABLE in c:\apache\htdocs\sp\ch2\example 2.20.12_21.12_22.12.php on line 50" error on line 50 (which is "<p><A HREF="$baseUrl">Home</A>\n".
Many thanks for any hints as to why.
Jon
I don't think the
[/PHO] tags help when trying to read the code so I have left them out.
[QUOTE]
<?php
// A standard header for a Web page
class StandardHeader {
// The header HTML is stored here
var $header = ' ';
// The constructor, taking the name of the page
function StandardHeader($title)
{
$html =
"
<html>\n
<head>\n
<title> $title </title>\n
</head>\n
<body>\n
<h1>$title</h1>\n
";
$this->setHeader($html);
}
// General method for adding to the header
function setHeader($string)
{
if (!empty($this->header)) {
$this->header .= $string;
} else {
$this->header = $string;
}
}
// Fetch the header
function getHeader()
{
return $this->header;
}
}
// Subclass for dealing with Categories, building a breadcrumb menu
class CategoryHeader extends StandardHeader {
// Constructor, taking the category name and the pages base URL
function CategoryHeader($category, $baseUrl)
{
// Call the parent constructor
parent::StandardHeader($category);
// Build the breadcrumbs
$html =
"
<p><A HREF="$baseUrl">Home</A>\n
<A HREF="$baseUrl?category=$category">$category</A></p>\n
";
// Call the parent setHeader() method
$this->setHeader($html);
}
}
// Set the base URL
$baseUrl = '12.php';
// An array of valid categories
$categories = array('PHP', 'MySQL', 'CSS');
// Check to see if we're adding a valid category
if (isset($_GET['category'] && in_array($_GET['category'], $categories)) {
// Instantiate the subclass
$header = new CategoryHeader($_GET['category'], $baseUrl);
} else {
// Otherwise it's the home page. Instantiate the Parent class
$header = new StandardHeader('Home');
}
// Display the header
echo $header->getHeader();
?>
<h2>Categories</h2>
<p><A HREF="<?php echo $baseUrl; ?>?category=PHP">PHP</A></p>
<p><A HREF="<?php echo $baseUrl; ?>?category=MySQL">MySQL</A></p>
<p><A HREF="<?php echo $baseUrl; ?>?category=CSS">CSS</A></p>
</body>
</html>
[/QUOTE]