Include files in a PHP page

Source: Internet
Author: User

If you have duplicate code in multiple files, you can write this part of the code to a file, and then include the file in the desired place. Note that in this file, you only need these duplicate code, and do not need any other format or anything, the filename can be random, suffix can not be.


By using the Include file, you can easily include the same content on multiple pages in your own site. An include file is a file that is dynamically included in a Web page when it is rendered in a browser.

Include files to simplify the administration of your site. For example, you can create content such as page banners, site information blocks, or menus that you want to include on multiple pages in your site. This way, when you need to change the content, you only have to make changes in a single file, and the changes are reflected on each page where the containing file resides.

The PHP include statement is a block of code that extracts the contents of an external file into a Web page. The following is an example of two PHP include statements:

<?php include (' aa.php ');?>

<?php include_once "./side/side";?>

There are two basic PHP include functions:include () and require (). The two behave the same way, but the errors are returned differently. The include () function continues to process the rest of the page, even if it is not parsed correctly, and displays a warning in the Web page where the containing file should be displayed. If the require () function references a missing file, the function stops processing the page and displays the error page in the browser.

The include_once () and require_once () functions specify that an include file can be used only once in a Web page. If the two include () functions refer to the same include file, only the first include () function is displayed in the browser.

Microsoft Expression Web support uses four different files as include files: HTML, INC, PHP, and TXT files. In addition, you can create nested include files. For example, you can create an include file that includes a reference to another include file.


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.