note 39131 added to function.include
| From: | shojiro at dogknife dot tenriats dot com | Date: | Sun, 18 Jan 2004 08:27:26 +0000 |
| Subject: | note 39131 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63764@lists.php.net to get a copy of this message | ||
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. ;)
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39131
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39131&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39131&report=yes
Search -- http://master.php.net/manage/user-notes.php