Includes within <<<EOD //here EOD;?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Includes within <<<EOD //here EOD;?

Post 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;
?>
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Includes within <<<EOD //here EOD;?

Post 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">&copy; $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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Includes within <<<EOD //here EOD;?

Post 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.
(#10850)
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Includes within <<<EOD //here EOD;?

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Includes within <<<EOD //here EOD;?

Post 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).
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Includes within <<<EOD //here EOD;?

Post by JAB Creations »

Oh I had three? Then I was tired when I posted! :mrgreen: Yeah I figured the function variables were local...ok ok I'm getting used to scope then thanks! :D
Post Reply