The include () or require () function lets you insert the contents of a file in the file before the server executes the php tutorial file. These two functions are the same in all other respects, except that they handle errors differently. The include () function generates a warning (but the script continues to execute), whereas the require () function generates a fatal error (the script stops executing after an error occurs).
<html> <body>
<? php include ("header.php");?>
<h1> welcome to my home page </ h1>
<p> some text </ p>
</ body> </ html> The three files, "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 </ h1>
<p> some text </ p>
</ body> </ html>
require () function The require () function is the same as include (), except that it treats the error.
The include () function generates a warning (but the script continues to execute), whereas the require () function generates a fatal error (the script stops executing after an error occurs).
If you get an error when you reference a file with include (), you get an error message similar to the following:
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 inclusion (include_path = '.; c: php5pear') in c: homewebsitetest.php on line 5
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.