Free download web templates, books and more. Free php projects ,games and apps. GTA mods and more

Breaking

PHP Include and Require method

PHP Include File

include methods is external web page show in current page
PHP allows you to include file so that a page content can be reused many times. There are two ways to include file in PHP.
  1. include
  2. require

Advantage

Code Reusability: By the help of include and require construct, we can reuse HTML code or PHP script in many PHP scripts.

PHP include example

PHP include is used to include file on the basis of given path. You may use relative or absolute path of the file. Let's see a simple PHP include example.
File: menu.html
  1. <a href="http://samadroid.blogspot.com">Home</a> |   
  2. <a href="http://samadroid.blogspot.com/php-tutorial">PHP</a> |   
  3. <a href="http://samadroid.blogspot.com/java-tutorial">Java</a> |    
  4. <a href="http://samadroid.blogspot.com/html-tutorial">HTML</a>  
File: include1.php
  1. <?php include("menu.html"); ?>  
  2. <h1>This is Main Page</h1>  
Output:
home | php | java | html

This is Main Page


PHP require example

PHP require is similar to include. Let's see a simple PHP require example.
File: menu.html
  1. <a href="http://samadroid.blogspot.com">Home</a> |   
  2. <a href="http://samadroid.blogspot.com/php-tutorial">PHP</a> |   
  3. <a href="http://samadroid.blogspot.com/java-tutorial">Java</a> |    
  4. <a href="http://samadroid.blogspot.com/html-tutorial">HTML</a>  
File: require1.php
  1. <?php require("menu.html"); ?>  
  2. <h1>This is Main Page</h1>  
Output

home | php |java |html

This is Main Page