10 tips for PHP scripts go from zdnet--Include files _php tutorial

Source: Internet
Author: User
Tags variable scope
Include files if you are working on a large web site development project, then you must have a deep understanding of code reuse, for example, whether it is HTML or PHP code block, as long as the project is large enough, such as there are 1000 web pages, even if you only modify one time a year contains the copyright information footer will make you miserable. While PHP can help you reuse code through some functions, the function you want to use depends on what you intend to reuse. The main functions are: * include () and include_once () * require () and require_once () include () functions contain the given file, for example: include (/home/me/myfile); Any code in the include file will be executed within the variable scope of the code page where the include () is located. You can include static files on the server or target files that are contained on other servers by combining include () and fopen (). The include_once () function is similar to the Include () function, except that the function checks whether the code within the included file has been included in the current script. If the code is already included in the script, the function will no longer contain the corresponding file. The Require () function replaces itself with the contents of a given file. This substitution process occurs when the PHP engine compiles your code instead of executing the code phase, which is different from the include (), which is first computed and then added to the text block. The Require () function is mostly used for static elements, while the include () function is primarily used for dynamic elements. Similar to Include_once (), the require_once () function checks to see if the given code has been inserted into the block, and if so, the given code will not be inserted again in the document. I suggest you better use the Require function for information such as copyrights, static text, and other elements that do not contain variables, and those that rely on other scripts to implement their own content are best used with the Require function, for example: <title>Something</title> [A lot of content] On the other hand, I often use the include () function to put libraries or similar content outside the script: <title>Something</title> [A lot of content] You will surely ask, "So where are the files that were included or required?" "The answer is simple:" Your system. "However, sometimes, some code will contain security information such as database connection functions with usernames and passwords, in which case it is clear that you do not want these things to become part of the documentation to be known throughout the world." You can place the included files (included or required) anywhere on the system, as long as the user can access the files using PHP. You can also give these files the file name extension you wish to give, or do not set the extension. Using the include () and require () functions makes it easier to process elements that are ubiquitous or frequently changing on a Web site.

http://www.bkjia.com/PHPjc/531806.html www.bkjia.com true http://www.bkjia.com/PHPjc/531806.html techarticle include files if you are working on a large web site development project, then you must have a deep understanding of code reuse, for example, HTML or PHP code blocks, as long as the project is large enough ...

  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.