Monday, 16 June 2014

Difference between include() & require()

Hello friend ..today i am going to teach you about the both { Include() & Require() } main functions in php.Both has same meaning but in a different manner.

Include() function

Syntax=include('main.php');

For this we have to create the file with extention of  ".php",

<?php
<body>
<a href="http://www.example.com/index.php">Home</a> <br />
<a href="http://www.example.com/about.php">About Us</a> <br />
<a href="http://www.example.com/services.php">Services</a> <br />
<a href="http://www.example.com/portfolio.php">Portfolio</a> <br />
<a href="http://www.example.com/Contact.php">Contact Us</a>
</body>
?>

Now ,save this file as main.php.for including this file we have to create new file called index.php. Here we know about the importance or we can say that how to use a include function,

<?php include("main.php"); ?>
<p>Hello this is my first php website</p>
</html>

Require() function-

Try the same example ,by using the function require() in the place of include().The only different is that require() function gives fatal error if there is no file found.

<?php include("nofile.php"); ?>
<p>Hello this is my first website</p>


Output=It gives fatal error and stop the script.








Posted by Amit Tiwari

Thankyou,

If you have any doubt related to post and want to know more about this so just comment in the below comment box,I ll response asap.


No comments:

Post a Comment