What is the difference between include() and require() in php

  • Share
  • CevherShare
  • Share

include() and require() function does the same process of calling a php or html or js file.

When the included file (i.e., calling a file) is missing in its actual directory, then require() function will returns FATAL ERROR and include() function will return WARNING.

Read:  what is the use of include() and require() in php

include_once() function will include a file only when that file is not included before. This function is the recommended for including files, because including a file more than once will arise ERROR

require_once() function performs the same operation performed by include_once() function. The only difference between include_once() function and require_once() function is as like the difference between include() and require() that is include_once() function returns WARNING and require_once() function returns FATAL ERROR, when file is missing.

 

 Example for include() function and require() function

1
2
3
4
5
6
7
8
9
<?php

include('meta.php');

require('head.php');

echo "Require and include function";

?>
prasad

About prasad

Prasad K has written 111 post in this blog.