php include and require
In php include and require are almost same but the difference between these two is require generates fatal error and does not allow any valid syntax to be displayed where on the other hand include does allow the valid syntax to be displayed which should not be consider as good programming practice at all.
In the following examples we will see how these two statements include and require are different.
Example (using include):
<?php
include ('NewAjax.php');
echo "This is a line";
?>
Output:
Warning: include(NewAjax.php) [function.include]:
failed to open stream: No such file or directory in C:\wamp\www\php_advance\radioAjax.php
on line 2
Warning: include() [function.include]:
Failed opening 'NewAjax.php' for inclusion (include_path='.;C:\php5\pear') in
C:\wamp\www\php_advance\radioAjax.php on line 2
This is a line
Example (using require):
<?php
require('NewAjax.php');
echo "This is a line";
?>
Output:
Warning: require(NewAjax.php) [function.require]:
failed to open stream: No such file or directory in C:\wamp\www\php_advance\radioAjax.php
on line 2
Fatal error: require() [function.require]:
Failed opening required 'NewAjax.php' (include_path='.;C:\php5\pear') in
C:\wamp\www\php_advance\radioAjax.php on line 2
As above output, require generates Fatal error: and does not executes the valid lines as well.