English
German

PHP Require

PHP Require

Just like the previous lesson, the require command is used to include a file into your PHP code. However there is one huge difference between the two commands, though it might not seem that big of a deal.


Require vs Include

When you include a file with the include command and PHP cannot find it you will see an error message like the following:

Example:

<?php
include("noFileExistsHere.php");
echo "Hello World!";
?>
 

Output
Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/hiscript.php on line 2 Warning: main(): Failed opening 'noFileExistsHere.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/websiteName/FolderName/hiscript.php on line 2 Hello World!

Notice that our echo statement is still executed, this is because a Warning does not prevent our PHP script from running. On the other hand, if we did the same example but used the require statement we would get something like the following example.


PHP Tutorial,PHP Require, PHP Require example, learn PHP Require,explain example PHP Require online free training PHP Tutorial, PHP Tutorial example, learn PHP Require, online tutorial, download tutorial, PHP Tutorial books, PHP Tutorial videos, live videos PHP Tutorial, learn PHP Tutorial, PHP Tutorial topic PHP Require, live training PHP Tutorial, download free tutorial