Home >Backend Development >PHP Problem >How to call specified file in php

How to call specified file in php

(*-*)浩
(*-*)浩Original
2019-09-29 13:55:233534browse

The include and require functions in PHP can call content generated by other PHP. Generally speaking, the include (or require) statement will obtain all text/code/marks that exist in the specified file and copy them to the include statement. in the file.

How to call specified file in php

##PHP include and require statements: (recommended learning: PHP video tutorial)

Through the include or require statement, the contents of a PHP file can be inserted into 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

Therefore, if you want to continue execution and output results to the user, even if the included file is missing, 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.

Such as:

<html>
<body>
<h1>欢迎访问我们的首页!</h1>
<?php require &#39;header.php&#39;;?>
<p>一段文本。</p>
<p>一段文本。</p>
<?php include &#39;footer.php&#39;;?>
</body>
</html>

The above is the detailed content of How to call specified file 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