E Online Support - Free Software Download
What is the difference between include and require?
I am new to php,plz tell me where to use include() and where to use require() function. Thanks in advance
Shruti
Answer
1

The require statement is also used to include a file into the PHP code. However, there is one big difference between include and require; when a file is included with the include statement and PHP cannot find it, the script will continue to execute. If we do the same example using the require statement, the echo statement will not be executed because the script execution dies after the require statement returned a fatal error.
<html>
<body>

<h1>Welcome to my home page!</h1>
<?php include 'noFileExists.php';
echo "I have a $color $car.";
?>

</body>
</html>

output:
Welcome to my home page!

I have a .


While use require

<html>
<body>

<h1>Welcome to my home page!</h1>
<?php require 'noFileExists.php';
echo "I have a $color $car.";
?>

</body>
</html>


Output

Welcome to my home page!

Answer
2

The include() and require() are almost similar except the way they handle failures. include() produces a warning and require() produces a fatal error. To halt processing of the page, use require(). The same operation will not halt by using include(). It should be ensured that the include_path settings are proper. Both are used for inserting the file content into PHP file prior to its execution by the server.
Question*:
Description*:
Script:
Related To:
 PHP    HTML    CSS    JAVASCRIPT    JQUERY   
 AJAX    WINDOWS    GAMES    DRIVERS    MAC   
 LINUX    MOBILE    GADGETS   
Security Code:
1001
Enter Security Code:
 
Facebook   Linkedin   Skype   Twitter