The include statement will get all the text/code/tags present in the specified file and copy it to the file using the include statement.
#Included files are useful if you need to reference the same PHP, HTML, or text on multiple pages of your website.
PHP include and require statements(Recommended learning: PHP video tutorial)
The contents of PHP files can be inserted through the include or require statements Another PHP file (before the server executes it).
include and require statements are identical, except for error handling:
require generates a fatal error (E_COMPILE_ERROR) and stops the script
include only A warning (E_WARNING) is generated and the script continues
So if you wish to continue execution and output results to the user even if the include file is missing, then use include. Otherwise, in frameworks, CMS, or complex PHP application programming, always use require to reference key files to the execution flow. This helps improve application security and integrity in the event that a critical file is accidentally lost.
Including files saves a lot of work. This means you can create standard header, footer or menu files for all pages. Then, when the header needs updating, you simply update the header include file.
Syntax
include 'filename';<br/>
PHP include Example
Example 1
Suppose we have a file named " footer.php", like this:
<?php<br/>echo "<p>Copyright © 2006-" . date("Y") . " php.cn</p>";<br/>?><br/>
If you need to reference this footer file in a page, please use the include statement:
<html><br/><body><br/><h1>欢迎访问我们的首页!</h1><br/><p>一段文本。</p><br/><p>一段文本。</p><br/><?php include 'footer.php';?><br/></body><br/></html><br/>
The above is the detailed content of What does include mean in php. For more information, please follow other related articles on the PHP Chinese website!