The include() statement includes and evaluates the specified file.
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be include()ed using an URL instead of a local pathname. See Remote files and fopen() for more information.
An important note about how this works is that when a file is include()ed or require()ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
This happens each time the include() statement is encountered, so you can use an include() statement within a looping structure to include a number of different files.
$files = array ('first.inc', 'second.inc', 'third.inc'); for ($i = 0; $i < count($files); $i++) { include $files[$i]; } |
include() differs from require() in that the include statement is re-evaluated each time it is encountered (and only when it is being executed), whereas the require() statement is replaced by the required file when it is first encountered, whether the contents of the file will be evaluated or not (for example, if it is inside an if statement whose condition evaluated to false).
Because include() is a special language construct, you must enclose it within a statement block if it is inside a conditional block.