Include () or require () function. You can insert the content of a file into the file before the server executes the php Tutorial file. Except for the way they handle errors, the two functions are the same in other aspects. The include () function generates a warning (but the script continues to execute), and The require () function generates a fatal error (the execution will be stopped when an error occurs ).
<Html>
<Body>
<? Php include ("header. php");?>
<H1> welcome to my home page
<P> some text </p>
</Body>
</Html>
"Default. php", "about. php", and "contact. php" all reference the "menu. php" file. This is the code in "default. php:
<? Php include ("menu. php");?>
<H1> welcome to my home page
<P> some text </p>
</Body>
</Html>
Require () function
The require () function is the same as include (), but the difference is that it handles errors.
The include () function generates a warning (but the script continues to execute), and The require () function generates a fatal error (the execution will be stopped when an error occurs ).
If an error occurs when you reference a file through include (), an error message similar to the following is returned:
Php code:
<Html>
<Body>
<? Php
Include ("wrongfile. php ");
Echo "hello world! ";
?>
</Body>
</Html> error message:
Warning: include (wrongfile. php) [function. include]:
Failed to open stream:
No such file or directory in c: homewebsitetest. php on line 5
Warning: include () [function. include]:
Failed opening 'wrongfile. Php' for future Sion
(Export de_path = '.; c: php5pear ')
In c: homewebsitetest. php on line 5
Hello world!