The include and require functions in PHP can improve the website construction efficiency and maintenance in the website design. The details are as follows: the include function and the pre-processing command with the same name in C are different. it is a file name (for example, include (& quot; test. php & quot;), PHP calls the file Syntax
The include and require functions in PHP can improve the website construction efficiency and maintenance in the website design. The details are as follows:
The include function and the pre-processing command with the same name in C are different. it is a file name (for example, include ("test. php "), PHP calls the file at the include location, and tries to explain the file. The difference between the file and the function is that the code is parsed only when the include statement is executed, therefore, in the design, the if statement usually includes the advantage of calling, while the number of require H always contains the specified file, even if it is not executed in the if statement. You can see this problem in the discussion of the PHP mail list: require is faster than include, because PHP can insert the specified file into the script before the code can be read through. Therefore, in programming, if a file is included in a control block (such as if, switch, while, for), use include. In other cases, use the requirc function.
Why should we use include and require in PHP programs? First, it makes the code more readable. Second, it divides the site into modules, which enables you to write the scripts to be reused in the website design, it can be reused in the construction of the entire site and in future projects, without repeated work, greatly improving the work efficiency. Many web sites must rely on repeated elements, such as consistent navigation bars, which can be easily operated by users, but it poses a big problem for Site D construction and maintenance. Each page has a code block that must be repeated and pasted on it. Make it a module and include or rquire it on every required page. you only need to modify it once, that is, modify only the include script module. Therefore, during the construction of a website, which part of the site should be analyzed to be repeated? Then, the duplicate code is written into a module. The following is a way to divide the site module:
0. Information Screen 1. database and file actions 2. H number 3. layout 4. navigation bar.
The detailed measures are as follows:
The core of a website is its information page. Other things are embellishment. The screen can display HTML or PHP code to extract and format data from a database or file. these screens can be further divided into parts based on their quantity, this is more helpful for maintenance than other methods. The modules on the first screen correspond to the pages accessible on the site. Navigation and layout are available based on the location where the page appears on the site. In this way, the information screen module becomes the key to selecting other modules. Such as the website's news publishing system.
The Layout module displays the control content on the page. The main part of the content is the output of the screen module. Of course, there will also be other content such as top navigation and edge navigation, and the footer of each page may also have copyright and a file-based navigation bar. Layout releases all of these features. The Layout module can be changed in two ways. First. You can place elements in the transform and select those items for display. Index pages generally have different navigation elements than secondary pages. Similarly, the third-pole page may only return links to previous pages.
The navigation module can be simply listed as an HTML file about the third-level page link. Generally, you can use another color to indicate the link to the current region to indicate the region of your current site. Navigation can be the link list on the left of the page. Each button is an image. They change when the mouse is passed. You can create a module to determine the region based on the selected screen module. It is relatively easy to use the if statement to display a new version of the current region link.
When building a site, you are very likely to encounter repeated code segments. Function modules can be used to enable these functions.
Now, the introduction of include and require is here. I believe it will help you in website construction. In the encapsulation of the next database operation, include and require are applied, hoping to help you better understand and play a leading role.