Page 1 of 1
Includes within <<<EOD //here EOD;?
Posted: Tue Apr 01, 2008 11:01 pm
by JAB Creations
Code: Select all
<?php
$page = <<<EOD
// HTML stuff
// HTML stuff
// *** PHP includes, how can I adapt this PHP code for it to work?
// HTML stuff
// HTML stuff
// atempted to do '.include("file.php"). without success for example.
// HTML stuff
// HTML stuff
EOD;
?>
Re: Includes within <<<EOD //here EOD;?
Posted: Tue Apr 01, 2008 11:17 pm
by JAB Creations
Actually I have a
good question after I've saw this...
Code: Select all
<?php
// 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">© $year $copyright</div>
</body>
</html>
EOD;
return $page;
}
// Initialize the page variable
$page = '';
// Add the header to the page
$page = addHeader($page, 'Acme Widgets');
// Add something to the body of the page
$page .= <<<EOD
<p align="center">Watch our widgets wobble!</p>
EOD;
// Add the footer to the page
$page = addFooter($page, date('Y'), 'Acme Inc.');
// Display the page
echo $page;
?>
The $page variables are only available to the functions they are defined within, correct? I presume this is why there can be two exact case sensitive matching instances of the same variable on the same page?
Re: Includes within <<<EOD //here EOD;?
Posted: Wed Apr 02, 2008 12:44 am
by Christopher
The word "page" really don't not have an single meaning in PHP. You can have two separate variables with the same name in different scopes, classes, etc.
Re: Includes within <<<EOD //here EOD;?
Posted: Wed Apr 02, 2008 12:48 am
by JAB Creations
Would it be accurate to say that both $page variables are at the same level of scope, just in two different instances of that level of scope?
Re: Includes within <<<EOD //here EOD;?
Posted: Wed Apr 02, 2008 7:35 am
by Chris Corbyn
Which $page variables are you referring to?
You have two $page variables within your two functions (those are referred to as "local scope" since they're local to that function only). You also have a $page variable in the "global scope" (outside of any function or class).
Re: Includes within <<<EOD //here EOD;?
Posted: Wed Apr 02, 2008 1:42 pm
by JAB Creations
Oh I had three? Then I
was tired when I posted!

Yeah I figured the function variables were local...ok ok I'm getting used to scope then thanks!
