(Conversion) original PHPinclude and require statements: www.w3school.com. cnphpphp_includes.asp? Server-side inclusion (SSI) is used to create functions, headers, footers, or elements that can be reused on multiple pages. PHPinclude and require statements? In PHP, you can put the include and require statements in PHP before the server executes the PHP file.
Link: http://www.w3school.com.cn/php/php_includes.asp
?
Server-side inclusion (SSI) is used to create functions, headers, footers, or elements that can be reused on multiple pages.
PHP include and require statements
?
In PHP, you can insert a PHP file into another PHP file before the server executes the PHP file.
The include and require statements are used to insert useful code into other files in the execution stream.
Include is very similar to require, except for the differences in error handling:
- Require generates a fatal error (E_COMPILE_ERROR) and stops the script.
- Include will only generate warning (E_WARNING), the script will continue
Therefore, if you want to continue the execution and output the results to the user, use include even if the included files are lost. Otherwise, in the framework, CMS, or complex PHP application programming, always use require to reference key files to the execution stream. This helps improve application security and integrity when a key file is accidentally lost.
The inclusion of files saves a lot of work. This means that you can create a standard header, footer, or menu file for all pages. Then, when the page header needs to be updated, you only need to update the page header containing files.
Syntax
include 'filename';
Or
require 'filename';
Basic instances of PHP include and require statements
Suppose you have a standard page header file named "header. php ". To reference this header file on the page, use include/require:
Welcome to my home page!Some text.
Example 2
Suppose we have a standard menu file used on all pages:
"menu.php":echo 'HomeTutorialsReferencesExamplesAbout UsContact Us';
This menu file should be referenced on all pages of the website. This is a specific practice:
Welcome to my home page.Some text.
Example 3
Suppose we have a variable inclusion file ("vars. php "):
These variables can be used in the call File:
Welcome to my home page.
php include 'vars.php';echo "I have a $color $car"; // I have a red BMW?>
?
In addition to include and require, there are two functions similar to include_once and require_once. the two functions with the once suffix will automatically detect whether the included files are included, it can be used to prevent repeated inclusion (repeated inclusion of the same file may cause errors). However, it is precisely because it automatically detects whether repeated inclusion will result in a loss of performance.