Example of include () statement
The include () statement binds the specified file and evaluates them.
When a file is, the included code inherits the variable scope of the line in the statement stands. From this line, all available variables in the file in the calling script is available.
Example:
vars.php
<? php
$ color = ‘green’;
$ fruit = ‘appel’;
?>
test.php
<? php
echo “A $ color $ fruit”; / / A
include ‘vars.php’;
echo “A $ color $ fruit”; / / A green apple
?>
If the include in the calling script inside a function, does the entire code of the file exactly as if this code within this function had been defined. For this reason, this code is within the scope of the variables of this function.
<? php
function foo () (
global $ color;
include ‘vars.php’;
echo “A $ color $ fruit”;
)
/ * Vars.php is in the scope of foo (), *
* $ Fruit is outside this range *
* NOT available. $ color is because we *
* This variable as a globally defined * /
foo (); / / A green apple
echo “A $ color $ fruit”; / / A green
?>
When a file is included, parsing drops out of PHP mode at the beginning of the target file in HTML mode and returns at the end of the embedded file in the PHP-mode. Therefore, any code within the included file as PHP code to be valid PHP start and end tags.
If “URL fopen wrappers” are enabled in PHP (in the default configuration, this is the case) you can specify the file to a URL (via HTTP or other support wrappers) instead of a local pathname. If the target server interprets the target file as PHP code, you can file to the included variables in a URL request string as used with HTTP GET. Strictly speaking, this is not the same as this file and to this the scope of the father to inherit scripts, the script will be displayed on the remote server and then the result in the local script.

You must be logged in to post a comment.