Php files include (), require () _ PHP Tutorial

Source: Internet
Author: User
Php files include () and require. This article describes in detail the file call tests in php, including include (), require (), include_once (), require_once (), and many other exchange calls, if you have any need, refer to this article for details about the file call tests in php, including include (), require (), include_once (), require_once () for more information, see.


7.3.1 use of Include, can contain the same file multiple times

The code is as follows:

Include 'demo1. php ';

Include 'demo1. php ';

Include 'demo1. php ';

?>

The output result is as follows:

The code is as follows:

E10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359


--------------------------------------------------------------------------------

E10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359


--------------------------------------------------------------------------------

E10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359

7.3.2 Using include_once is no different from using include, but multiple calls only contain the same file once.

The code is as follows:

Include_once 'demo1. php ';

Include_once 'demo1. php ';

Include_once 'demo1. php ';

?>

The result is as follows:

The code is as follows:
E10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359

7.3.3 The require () statement contains and runs the specified file.

The code is as follows:

Require 'demo1. php ';

Require 'demo1. php ';

Require 'demo1. php ';

?>

The result is as follows:

The code is as follows:

E10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359


--------------------------------------------------------------------------------

E10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359


--------------------------------------------------------------------------------

E10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359

7.3.4 The require_once () statement contains and runs the specified file during script execution, but does not contain the same file repeatedly.

The code is as follows:

Require_once 'demo1. php ';

Require_once 'demo1. php ';

Require_once 'demo1. php ';

?>

The output result is as follows:

The code is as follows:
E10adc3949ba59abbe56e057f20f883e
7c4a8d09ca3762af61e59520943dc26494f8941b
3.14159265359 s

7.3.5 differences between include and require

If there is other code behind Include, when an error occurs in calling include, the subsequent code will continue to be executed, but require will not.

When calling a non-existent file, Include will give a warning, but will continue to execute the subsequent code.

The code is as follows:

Include 'demo11.php ';

Echo ('this is demo13.php ');

?>

The output result is as follows:

The code is as follows:

Warning: include (demo111.php) [function. include]: failed to open stream: No such file or directory in D: AppServwwwBasic7demo13. php on line 2

Warning: include () [function. include]: Failed opening 'demo111. php' for future Sion (include_path = '.; C: php5pear') in D: AppServwwwBasic7demo13. php on line 2
This is demo13.php

When Require calls a non-existent file, it will give an error and abort code execution.

The code is as follows:

Require 'demo111. php ';

Echo ('this is demo14.php ');

?>

The output result is as follows:

The code is as follows:

Warning: require (demo111.php) [function. require]: failed to open stream: No such file or directory in D: AppServwwwBasic7demo14. php on line 2

Fatal error: require () [function. require]: Failed opening required 'demo111. php' (include_path = '.; C: php5pear') in D: AppServwwwBasic7demo14. php on line 2

Callback (), require (), include_once (), require_once (), and other exchange calls. if you need them, please refer to them...

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.