In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
The main content of this article is to explain "is there any document citation method for php"? interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "is there any file citation method for php"?
There are four file reference methods: 1, with the include statement, the syntax "include 'file name'", when there is an error in the included file, the system will report an error, but the program will continue to execute; 2, with the require statement, the syntax "require 'file name'"; 3, with the include_once statement and so on.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
File reference (file inclusion) refers to the use of including the entire contents of another source file in the current source file, often referred to as bringing in an external file. Referencing external files can reduce the reusability of code and is an important skill in PHP programming.
Four very simple but useful reference statements are provided in PHP: the include statement, the require statement, the include_once statement, and the require_once statement. There are some differences in the use of these four sentences.
1. Include statement
When you use the include statement to include an external file, the external file is included only when the code executes the include statement, when an error occurs in the included external file, the system gives a warning, and the entire PHP program continues to execute downward.
The syntax format of the include statement is as follows:
Include ('filename') / / or include' filename'
Where filename is the file path to be included (both relative and absolute paths are fine), and filename is a string, so you need to wrap it in single or double quotation marks. At the same time, the parentheses after the include can also be omitted. When omitting the parentheses, the include needs to be separated from the following filename with a space.
For demonstration purposes, let's prepare a demo.php file and simply define a $str variable in it, as shown below:
[example] use the include statement to include the demo.php file, the code is as follows:
The running results are as follows:
Https://www.yisu.com/
2. Require statement
The use of the require statement is similar to the include statement, which implements the reference to an external file. Before the PHP file executes, the PHP parser replaces the require statement with the entire contents of the referenced file, then forms a new PHP file with statements other than the require statement, and finally executes the program code according to the new PHP file.
Note: because the require statement is equivalent to completely copying the contents of another source file into this file, it is generally placed at the beginning of the source file to reference the public function files and public class files that need to be used.
The require statement is almost exactly the same as the include statement, except that when the included file is not saved or there is an error, the require statement issues a Fatal error error and terminates program execution, while include issues a Warining warning but the program continues to execute.
The syntax format of the require statement is:
Require (filename) / / or require 'filename'
The parameter filename is the file path to be included, and its characteristics are the same as the parameters in the include statement.
[example] use the require statement to include the demo.php file defined above, the code is as follows:
The running results are as follows:
Https://www.yisu.com/
3. Include_once statement
The include_once statement is similar to the include statement, except that if the included file is already included, it will not be included again. Include_once ensures that the same file is included only once during script execution to avoid problems such as function redefinition and variable reassignment.
Let's adjust the demo.php file defined above, as follows:
[example] use the include_once statement to include the demo.php file, the code is as follows:
The running results are as follows:
Https://www.yisu.com/
4. Require_once statement
The require_once statement is an extension of the require statement, and its function is basically similar to the require statement, except that when applying the require_once statement, it will first check whether the file to be included has been included elsewhere in the program, and if so, it will not repeat to include the file again.
[example] use the require_once statement to include the demo.php file, the code is as follows:
The running results are as follows:
Https://www.yisu.com/ so far, I believe that you have a deeper understanding of "php has no file citation method", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.