How to call different PHP file paths: 1. Get all the text in the specified file through the include statement and copy it to the file using the include statement. The syntax is such as "include 'filename';"; 2 , insert the contents of the PHP file into another PHP file through the require statement. The syntax is "require 'filename';".
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
php How to call different php file paths?
Very simple!
include ("File Path"); or require ("File Path");
For example
include("./a.php"); require("./a.php");
The difference is that the required imported file does not exist. The script will stop;
include will continue to run;
Extension:
include (or require) statement will obtain the specified file All text/code/markup that exists and is copied 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 a warning (E_WARNING), and the script will continue
So if you want to continue execution and output results to the user even if the included file is missing, then 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.
Grammar
include 'filename';
or
require 'filename';
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to call different php file paths in php. For more information, please follow other related articles on the PHP Chinese website!