Monday, May 9, 2016

PHP Include

PHP Include

The include statement includes and evaluates the specified file.

The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.

Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

Syntax

include 'filename';

or

require 'filename';

Example :

File my_include.php :
  1. <?php  
  2. $sports1 = "football";  
  3. $sports2 = "cricket";  
  4. ?>  
File myfile.php, which includes my_include.php :
  1. <?php  
  2. include('my_include.php');  
  3. echo "I prefer&nbsp;".  $sports1 ."&nbsp;  
  4. than&nbsp;".  $sports2;  
  5. ?>  

Output

I prefer football  than cricket

No comments:

Post a Comment