require() and include() Functions in PHP


In PHP, We have two functions to use one php file into another php file, There are include() and require() function, 

 

In require(), It produces a warning and a fatal error i.e. the script will not continue execution. in include(), It produces a warning but it continue execution.

 

consider an example.

 

<?php

 

include(‘filename.php’);   // include syntax

 

require(‘filename.php’);  // require syntax

 

?>

 

Below will be the sample php file with some code. The filename for the below php is phpfilename.php

 

<?php

 

echo “This is from out side php file”;

 

?>

 

Once you have included a php file into another php file, If you see the source for the page in browser you can find the codes like this….This is the sample php code, In this example I have included phpfilename.php

 

<html>

 

<body>

 

<h1>Welcome to TechMarket Blog,</h1>

 

<?php

 

echo “This is from out side php file”;

 

?>

 

</body>

 

</html>

 

In require(), once you have written a code using require(), If your script has any error then require() will show warning message and fatal error and stop the execution. But, In case of include() it will show warning message and will continue the execution.

 

The Conclusion of this post is that you can know the difference about the require() and include()

 

in php, If you have any queries and php errors you can contact me.

 

Advertisements

Tell us Your Suggestion

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s