PHP include and require in the two functions, can be in the design of the site to improve the site's construction efficiency and maintenance, now detailed explained as follows:
The Include function differs from the preprocessing command of the same name in C, which is a given file name (for example: include ("test.php")), and PHP uses the file for the location of the include and tries to interpret the file, which differs from the function in that The code is parsed only when an include statement is executed, so it is common to include calls in the IF statement in the design, whereas the Require H number always contains the specified file, even if it is not executed in the IF statement. You can see this in the discussion of the PHP mailing list: Require is faster than include, because PHP can insert the specified file into the script in the early stages of the read-through code. So in the program design, if a file is contained in a control block (for example: if,switch,while,for), use include, and other cases use the REQUIRC function.
Why should we use include and require in PHP programs? First of all, because this makes the code more readable, and secondly, it can be divided into modules, which allows you to design in the site as long as you write the script to be reused, you can be in the construction of the entire site and later in the project reuse, and do not need you to repeat work, greatly improve the efficiency. Many web sites must rely on repetitive features, such as a consistent navigation bar, which makes it easy for users to operate, but is a big problem for building and maintaining site D. Each page has a code block that must be duplicated on top of it. Make it into a module and include or rquire it in each of the required pages, and modify it only once, that is, only the script module of the include can be modified. So in the construction of a website, should analyze the site that part is duplicated? Then write the duplicated code into the module. Here is a way to partition the site module:
0, Information screen 1, database and file action 2, H number 3, layout 4, navigation bar.
The detailed measures are as follows:
The core of the site is the information page it contains, and everything else is dotted. The screen can be either HTML or PHP code that extracts and formats data from a database or file, which can continue to be divided into sections based on their number, which is more useful for maintenance than other methods. The modules on the first screen correspond to the pages that are accessible on the site. Depending on where the page appears on the site, you have the appropriate navigation and layout. This Information screen module becomes the key to select the remaining modules. such as the website of the press release system.
The layout module controls where the content appears on the page. The main part of the content is the output of the screen module. Of course there will be other content such as top navigation and side navigation, and may also have a copyright and a file-based navigation bar in the footer of each page. The layout puts all this out. There are two ways to transform a layout module. First of all. You can place elements in the transform and select those things to display. Index pages generally have different navigational elements than level two pages. The same third-pole page may only return links to previous pages.
The navigation module can be simply listed as an HTML file for a three-level page link. Usually you can indicate the area of the site to which the user is currently located by indicating a link to the current area with another color. The navigation can be a list of links on the left side of the page. Each button is an image. They change when the mouse is passed. You can create a module that determines the area based on the selected screen module. In contrast, it is easier to use an if statement to display a transformed version of a link to the current region.
When you build your site, it is very likely that you will encounter repeated snippets of code. function modules can be used to put these functions up.
All right, the introduction of include and require is here, I believe it will help you in the construction of the website. The application of include and require in the encapsulation of the next database operation is expected to help the big understanding and play a role.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service