1. What’s the use?
Server Side Include (SSI) is used to create functions, headers, footers or elements that can be reused on multiple pages. Included files reuse files and save a lot of work.
2. How to use?
include ‘filename’;
Or
require 'filename';
1.php
<code><span><?php</span><span>echo</span><span>"Hello "</span>; <span>include</span><span>'2.php'</span>; <span>?></span></code>
2.php
<code><span><span><?php</span><span>echo</span><span>"World."</span>; <span>?></span></span></code>
You will get 1.php when you access it in the browser (note that 1.php and 2.php are placed at this time (in the same folder): Hello World.
3. What is the difference between include and require?
In terms of error handling:
require will generate a fatal error (E_COMPILE_ERROR) and stop the script
include will only generate a warning (E_WARNING) and the script will continue
Please use this time:
Please use require at this time: when the file is requested by the application.
Use include here: when the file is not required and the application should continue running if the file is not found.
Copyright statement: This article is an original article by Lshare. If you need to reprint it, please contact me. If you have any questions, please comment or send a private message.
The above introduces include and require in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.