note 39131 deleted from function.include by betz
| From: | betz@php.net | Date: | Sun, 18 Jan 2004 10:19:13 +0000 |
| Subject: | note 39131 deleted from function.include by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63769@lists.php.net to get a copy of this message | ||
Note Submitter: shojiro@dogknife.tenriats.com
----
include() is great if you don't want to add too much code to a single file, and you'd
rather spread it out so it can be edited more easily. ie.
<?php include("left1.php"); ?>
Script here.
<?php include("last1.php"); ?>
It's great for when you don't want to have to go through layouts with 100's of lines
of code.
Also, if you define a variable before your include, you can then call on it in your included file.
ie.
left1.php
<?php print "<html><head><title>MySite.com:
$page</title></head>"; ?>
Now, we'd define the variable, then include the file.
<?php $page = "Include"; include("left1.php"); ?>
This would add the defined variable to the script so it would now output <?php print
"<html><head><title>MySite.com: Include</title></head>";
?>
Also, you may want to avoid making infinite loops with includes. Here's a mistake I made
once.... I include a file at the end of my left1.php script.
<?php //I put lots of HTML before this....
include("middle1.php"); ?>
Then, in my middle1.php script I did this:
<?php //some HTML again.....
include("left1.php"); ?>
I accessed the file via my browser, only to find that my webpage never ended. ;)