The two functions in include and require in PHP can improve website construction efficiency and maintenance in website design. They are explained in detail as follows:
The include function is different from the preprocessing command of the same name in C. It is Once a file name is given (such as: include("test.php")), PHP will call the file to the include location and try to interpret the file. The difference between it and the function is that the code only executes the include statement. is parsed, so the design usually includes the call in the if statement to take advantage of this; the require H number always includes the specified file, even if it is located in a place that is not executed in the if statement. You can see this problem in the discussion on the PHP mailing list: require is faster than include because PHP can insert the specified file into the script in the early stage of reading the code. Therefore, in programming, if a file is included in a control block (such as if, switch, while, for), include is used, and in other cases, the requirec function is used.
Why should we use include and require in PHP programs? First of all, because it makes the code more readable, and secondly because it can divide the site into modules, which allows you to build and build the entire site as long as you write the scripts to be reused in the design of the site. It can be reused in future projects without the need for you to repeat work, which greatly improves work efficiency. Many web sites must rely on some repetitive elements, such as a consistent navigation bar, which can facilitate user operations, but creates great problems in building and maintaining the site. Each page has blocks of code taped to it that must be repeated. Make it into a module and include or rquire it in every required page. When modification is needed, you only need to modify it once, that is, only modify the included script module. So when building a website, you should analyze which parts of the site are duplicated? Then write the repeated code into modules. The following is a way to divide the site modules:
0. Information screen 1. Database and file actions 2. H number 3. Layout 4. Navigation bar.
The details are as follows:
The core of the website is the information page it contains, and other things are embellishments. What is displayed on the screen can be HTML or PHP code, extracting and formatting data from a database or file. These screens can be further divided into sections based on their number, which is easier to maintain than other methods. The modules on the first screen all correspond to accessible pages on the site. Depending on where the page appears on the site, there can be corresponding navigation and layout. In this way, the information screen module becomes the key to selecting other modules. Such as the news release system of the website.