PHP Include File PHP
- PHP Tutorial
- What is PHP
- Install PHP
- PHP Example
- PHP Echo
- PHP Print
- PHP Variables
- PHP $ and $$ Variables
- PHP Constants
- Magic Constants
- PHP Data Types
- PHP Operators
- PHP Comments
- PHP Boolean
- PHP is_bool() function
- PHP Integer
- PHP is_int() function
- PHP Float
- PHP is_float Function
- PHP Compound Types
- PHP Special Types
- PHP is_null() function
- PHP If Else
- PHP Switch
- PHP For Loop
- PHP While Loop
- PHP do while loop
- PHP Break
- PHP Functions
- PHP Parameterized Function
- PHP Call By Value
- PHP Call By Reference
- PHP Default Argument Values Function
- PHP Variable Length Argument Function
- PHP Recursive Function
- PHP Arrays
- PHP Indexed Array
- PHP Associative Array
- PHP Multidimensional Array
- PHP Array Functions
- PHP String
- PHP String Functions
- PHP Math functions
- PHP Form Handling | GET and POST method
- PHP Include File
- PHP Cookie
- PHP Session
- PHP File Handling
- PHP Open File
- PHP Read File
- PHP Write File
- PHP Append to File
- PHP Delete File
- PHP File Upload
- PHP Download File
- PHP Mail
- PHP MySQL Connect
- PHP MySQL Create Database
- PHP MySQL Create Table Example
- PHP MySQL Insert Record
- PHP Prepared Statements
- PHP MySQL Update Record
- PHP MySQL Delete Record
- PHP MySQL Select
- PHP MySQL Order By
- PHP Limit Data MySql
- PHP JSON
- PHP XML Parsers
- PHP SimpleXML Parser
- PHP SimpleXML - Get Node/Attribute Values
- PHP XML Expat Parser
- PHP XML DOM Parser
- PHP - AJAX intro
- MySQL CREATE VIEW
PHP Include File
PHP Include File
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.
- include
- 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
- <a href="https://www.javatpoint.com">Home</a> |
- <a href="https://www.javatpoint.com/php-tutorial">PHP</a> |
- <a href="https://www.javatpoint.com/java-tutorial">Java</a> |
- <a href="https://www.javatpoint.com/html-tutorial">HTML</a>
File: include1.php
- <?php include("menu.html"); ?>
- <h1>This is Main Page</h1>
Output:
This is Main Page
PHP require example
PHP require is similar to include. Let's see a simple PHP require example.
File: menu.html
- <a href="https://www.javatpoint.com">Home</a> |
- <a href="https://www.javatpoint.com/php-tutorial">PHP</a> |
- <a href="https://www.javatpoint.com/java-tutorial">Java</a> |
- <a href="https://www.javatpoint.com/html-tutorial">HTML</a>
File: require1.php
- <?php require("menu.html"); ?>
- <h1>This is Main Page</h1>
Output:
This is Main Page
PHP include vs PHP require
If file is missing or inclusion fails, include allows the script to continue but require halts the script producing a fatal E_COMPILE_ERROR level error.