Home > Backend Development > PHP Tutorial > include and require in PHP

include and require in PHP

WBOY
Release: 2016-08-08 09:19:57
Original
940 people have browsed it

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>
Copy after login

2.php

<code><span><span><?php</span><span>echo</span><span>"World."</span>;
<span>?></span></span></code>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template