您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php中的include和require的区别_PHP教程

2024/3/25 16:29:33发布18次查看
php中的include和require的区别 主要关注红色标记语句即可。
the include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.
including files is very useful when you want to include the same php, html, or text on multiple pages of a website.
php include and require statementsit is possible to insert the content of one php file into another php file (before the server executes it), with the include or require statement.
the include and require statements are identical, except upon failure:
require will produce a fatal error (e_compile_error) and stop the scriptinclude will only produce a warning (e_warning) and the script will continueso, if you want the execution to go on and show users the output, even if the include file is missing, use the include statement. otherwise, in case of framework, cms, or a complex php application coding, always use the require statement to include a key file to the flow of execution. this will help avoid compromising your application's security and integrity, just in-case one key file is accidentally missing.
including files saves a lot of work. this means that you can create a standard header, footer, or menu file for all your web pages. then, when the header needs to be updated, you can only update the header include file.
syntaxinclude 'filename';
or
require 'filename';
php include examplesexample 1assume we have a standard footer file called footer.php, that looks like this:
to include the footer file in a page, use the include statement:
example
welcome to my home page!
some text.
some more text.
run example ?
example 2assume we have a standard menu file called menu.php:
all pages in the web site should use this menu file. here is how it can be done (we are using a
element so that the menu easily can be styled with css later):example
welcome to my home page!
some text.
some more text.
run example ?
example 3assume we have a file called vars.php, with some variables defined:
then, if we include the vars.php file, the variables can be used in the calling file:
example
welcome to my home page!
run example ?
php include vs. requirethe require statement is also used to include a file into the php code.
however, there is one big difference between include and require; when a file is included with the include statement and php cannot find it, the script will continue to execute:
example
welcome to my home page!
run example ?if we do the same example using the require statement, the echo statement will not be executed because the script execution dies after the require statement returned a fatal error:
example
welcome to my home page!
run example ?
use require when the file is required by the application.
use include when the file is not required and application should continue when file is not found.
http://www.bkjia.com/phpjc/845436.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/845436.htmltecharticlephp中的include和require的区别 主要关注红色标记语句即可。 the include (or require) statement takes all the text/code/markup that exists in the specified file and...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product