Include Functions in PHP

Include Functions in PHP

Including files in PHP is a handy feature when you want to include the same content or design in multiple pages such as header, footer, sidebar, etc.  In PHP, four include functions available, which we will learn and see the difference between them.

1.include() function: In the include function, write your file path where your file exists. In the include() function, if we write the wrong path sometimes due to typing mistake, then it will throw an error on the particular area where you are trying to include the file rest of code will be working fine.

Example: include(‘includes/header.php’);

This example includes folder name, and header.php is the file name.

2.require() function: In require function, simply write your file path where your file exists. In require() method, if we write the wrong path due to typing mistake, then it will throw an error, and it halts the execution of complete code means your file will not work.

Example: require(‘includes/header.php’);

3.include_once() function: include_once() is improved version of include() function. It is latest include function, sometimes we include file multiple time by mistake then it will help. It will not repeat our design means it does not accept the same file multiple times.

Example: include_once(‘includes/header.php’);

4.require_once() function: require_once() is an improved version of require function work same require, but there is a slight improvement; it does not accept the same file multiple times.

Example: require_once(‘includes/header.php’);

 

Categories: web development php

Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 20 Days

Crash : 7 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 7 Month

Fastrack : 4 Month

Crash : 2 Month

Related Blogs

Request For Demo