Include and require in PHP

Source: Internet
Author: User

One, what is the use?

Server-side inclusions (server Side Include,ssi) are used to create functions, headers, footers, or elements that can be reused on multiple pages. The Include file reuses the file and saves a lot of work.

Second, how to use?

Include ' filename ';
Or
Require ' filename ';

1.php


   
    echo"Hello ";include'2.php';?>

2.php


    
     echo"World.";?>

In the browser access 1.php will get (note that at this point 1.php and 2.php are placed in the same folder):Hello World.

Iii. What is the difference between include and require?

In terms of error handling:
Require generates a fatal error (E_COMPILE_ERROR) and stops the script
Include only generates a warning (e_warning), and the script continues

Please use at this time:
Please use require at this time: when the file is requested by the application.
Use include at this point: when the file is not required, and the application should continue to run when the file is not found.

Copyright NOTICE: This article for Lshare original article, need to reprint please contact me, have questions welcome comments or private messages.

The above introduces the include and require in PHP, including the content, I hope that the PHP tutorial interested in a friend to help.

  • Related Article

    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.