Home >Backend Development >PHP Problem >How to call specified file in php
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.
##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 'header.php';?> <p>一段文本。</p> <p>一段文本。</p> <?php include 'footer.php';?> </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!