PHP Require Statement

The php require statement is used when you want the code to be executed anyhow else the file should stop running. When you have some code that should be presented on the page then use require statement. The require statement stop running the php code if it doesn’t find the file name and shows the error.

Example:

[php]<?php require ‘noFileExists.php’;
echo "I have a $color $car.";
?>[/php]

Code Explanation

In the above code we are using require statement to get the file name “noFileExists.php“. If the server doesn’t find the file then will not run the code. You will not get the echo statement showing the text “I have a $color $car.”

Related Posts

Leave a Reply