10 tips for PHP scripts transferred from ZDNet--include files_PHP tutorial

WBOY
Release: 2016-07-13 17:28:08
Original
701 people have browsed it

Include files If you are currently working on a large-scale Web site development project, then you must have a deep understanding of code reuse. For example, whether it is HTML or PHP code blocks, as long as the project is large enough, such as 1,000 Web pages, you can Even modifying the footer containing copyright information only once a year will make you miserable. PHP can help you reuse code through some functions. The specific functions you want to use depend on the content you plan to reuse. The main functions are: * include() and include_once() * require() and require_once() The include() function includes a given file, such as: include(/home/me/myfile); Any code in the included file Will be executed within the variable scope of the code page where include() is located. You can include static files on the server or include object files on other servers by using include() and fopen() in combination. The include_once() function is similar to the include() function, except that this function checks whether the code in the included file has been included by the current script. If the code is already included in the script, the function no longer includes the corresponding file. The require() function replaces itself with the contents of the given file. This replacement process occurs when the PHP engine compiles your code rather than executing it, which is different from include(), which is first calculated and added to the document. The require() function is mostly used for static elements, while the include() function is mainly used for dynamic elements. Similar to include_once(), the require_once() function checks whether the given code has already been inserted into the document. If so, the given code will not be inserted into the document again. I recommend that you use the require function for information such as copyright, static text, and other elements that do not have variables. It is also best to use the require function for elements that rely on other scripts to implement their content, such as:

Something [a lot of content] // insert copyright require(/home/me/mycopyright); ?> On the other hand, I often use the include() function to put libraries or similar content into scripts Outside: // get my function library include(/home/me/myfunctions); // do PHP things with my functions ?> Something [a lot of content] You will definitely ask: "So, is included or required Where do the files come from? "The answer is simple: "Your system." However, sometimes some code contains security information such as database connection functions with usernames and passwords. In such cases, it is obvious that You don't want these things to become part of the document and be known to the whole world. You can place included files (included or required) anywhere on the system, as long as the files are accessible to users using PHP. You can also give these files any file extension you wish, or no extension at all. Use the include() and require() functions to make elements that are ubiquitous or frequently changing on a Web site easier to handle.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531806.htmlTechArticleIncluded files If you are currently working on a large-scale Web site development project, then you must have a deep understanding of code reuse , for example, whether it is HTML or PHP code blocks, as long as the project is large enough...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!