Home >Backend Development >PHP Problem >What is the usage of include in php

What is the usage of include in php

WBOY
WBOYOriginal
2022-02-22 10:46:186377browse

In PHP, the include statement is used to get all the text, code, and tags present in the specified file and copy them to the file using the statement. Before the server executes, the contents of the PHP file are inserted into another PHP files.

What is the usage of include in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What is the usage of include in php

The include (or require) 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

The include or require statements allow you to insert the contents of a PHP file into another PHP file (before the server executes it).

The include and require statements are identical, except for error handling:

  • require will generate a fatal error (E_COMPILE_ERROR) and stop the script

  • include only generates warnings (E_WARNING) 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 please 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';

or

require 'filename';

The contents of the public.php file are as follows:

What is the usage of include in php

##include Add include to the file Then add the public file in quotation marks.

What is the usage of include in php

Run the include file in the browser to view the results.

What is the usage of include in php

Recommended study: "

PHP Video Tutorial"

The above is the detailed content of What is the usage of include in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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