PHP Tutorial
What is PHP Environment Setup of PHP PHP Syntax PHP Comments PHP Echo & print PHP Variables PHP Scope Variables PHP $ and $$ Variable PHP Constants PHP Operators PHP Data TypesPHP Conditional Statements
PHP Loop Type
PHP Arrays
PHP String PHP FunctionsPHP Form Examples
Form Intro Get & Post Form Validation / Required PHP Complete FormPHP Advanced
PHP Include / Require PHP Date & Time PHP Session PHP Cookies PHP File Handling PHP Open File PHP Read File PHP Write File PHP Append File PHP Delete File PHP File Upload PHP Sending Mail PHP Error HandlingPHP Include / Require
PHP includes and requires are mechanisms that allow you to include the content of one PHP file into another PHP file.
This can be useful in situations where you have common code that you want to reuse across multiple pages, or when you want to break up a large PHP file into smaller, more manageable pieces.
There are two main ways to include files in PHP:
1) include()
2) require()
The main difference between these two functions is how they handle errors. If the file being included cannot be found by the include() function, a warning is issued and the script continues to execute. If the file being required cannot be found by the require() function, a fatal error is issued and the script stops executing.
Here is an example of how to use the include() function:
<?php
include 'navbar.php';
// Other page content goes here
include 'footer.php';
?>
In this example, the content of the "navbar.php" and "footer.php" files will be included in the current PHP file.
Here is an example of how to use the require() function:
<?php
require 'navbar.php';
// Other page content goes here
require 'footer.php';
?>
In this example, the "navbar.php" file and the "footer.php" file are required by the current PHP file. If either of these files cannot be found, a fatal error will be issued and the script will stop executing.
Elevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date