Learn PHP


The include statement includes and evaluates the specified file.

The documentation below also applies to require.

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include will finally check in the calling script's own directory and the current working directory before failing. The include construct will emit a warning if it cannot find a file; this is different behavior from require, which will emit a fatal error.

If a path is defined — whether absolute (starting with a drive letter or \ on Windows, or / on Unix/Linux systems) or relative to the current directory (starting with . or ..) — the include_path will be ignored altogether. For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file.

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.


			$color = 'green';
			$fruit = 'apple';



			echo "A $color $fruit"; // A

			include 'vars.php';

			echo "A $color $fruit"; // A green apple


		  	function foo()
			    global $color;

			    include 'vars.php';

			    echo "A $color $fruit";

			/* vars.php is in the scope of foo() so     *
			* $fruit is NOT available outside of this  *
			* scope.  $color is because we declared it *
			* as global.                               */

			foo();                    // A green apple
			echo "A $color $fruit";   // A green

		  	include 'http://www.example.com/file.txt?foo=1&bar=2';

			// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
			// local filesystem.
			include 'file.php?foo=1&bar=2';

			// Works.
			include 'http://www.example.com/file.php?foo=1&bar=2';

			$foo = 1;
			$bar = 2;
			include 'file.txt';  // Works.
			include 'file.php';  // Works.

PHP Tutorials






Echo and Print Statement

Data Types



Number Convert

PHP String

php variable substitution in string

php string element

php string function

php addcslashes function

php addslashes function

php get magic quotes gpc function

php get meta tags function

php urlencode function

PHP $ and $$ Variables

PHP constant

PHP Magic Constants

PHP Static Variable

PHP Super Globals

PHP Globals

PHP Server

PHP reserved variable get

PHP reserved variable post

PHP reserved variable FILES

PHP reserved variable Cookies

PHP reserved variable Session

PHP reserved variable Request

PHP reserved variable environment

PHP Operator

PHP Arithmetic Operator

PHP Comparison Operator

PHP Incrementing and Decrementing Operators

PHP Identical Operators

PHP Logical Operators

PHP String Operators

PHP Ternary Operators

PHP Execution Operators

PHP Operator Precedence

PHP Array Operator

PHP Class

PHP Class Inheritance

PHP constructor and destructor

PHP abstract class

PHP class access control

PHP statement

PHP If statement

PHP else statement

PHP else if statement

PHP control structure statement

PHP while loop

PHP do while loop

PHP for loop

PHP for each loop

PHP break statement

PHP continue statement

PHP declare statement

PHP return statement

PHP require statement

PHP include

PHP require once

PHP include once

PHP goto statement

PHP function

PHP function parameter

PHP function scope

PHP array

PHP array operator

PHP array element loop

PHP array foreach loop

PHP array multidimensional

PHP html forms

PHP get and post method

form redirect

file inclusion

file i/o