PHP heredoc syntax

Associate
Joined
25 Jul 2005
Posts
430
Hi,
I recently read a tutorial which suggested using heredoc syntax to add the content of an entire page to a single variable and then echo this value at the end of the code. Is this really a good idea, or would it be better to use lots of include files etc.
This is an example from the tutorial with only a small amount of content, later it goes on to add a lot more:

class Page {

// Generates the top of the page
function addHeader($page, $title)
{
$page .= <<<EOD
<html>
<head>
<title>$title</title>
</head>
<body>
<h1 align="center">$title</h1>
EOD;
return $page;
}

// Generates the bottom of the page
function addFooter($page, $year, $copyright)
{
$page .= <<<EOD
<div align="center">&copy; $year $copyright</div>
</body>
</html>
EOD;
return $page;
}
}

Any advice would be appreciated, thanks.:D
 
Back
Top Bottom