php require函数有什么用

PHPz
Release: 2020-09-05 13:56:02
Original
2583 people have browsed it

php require函数用于引入或者包含外部php文件,可以在执行流中插入写在其他文件中的有用的代码;当包含的外部文件发生错误时,系统将抛出错误提示,并且停止php文件的执行。

php require函数有什么用

php require函数有什么用?

require()是php的内置函数,作用是引入或者包含外部php文件,用于在执行流中插入写在其他文件中的有用的代码。

  工作原理:当本身php文件被执行时,则外部文件的内容就将被包含进该自身php文件中;当包含的外部文件发生错误时,系统将抛出错误提示,并且停止php文件的执行。

  注意:使用require时,一个文件存在错误的话,那么程序就会中断执行了,并显示致命错误 。

  比如cl.php,ts.php两个文件,ts.php要用到cl.php文件中的函数,需要在ts.php中引入或者包含cl.php即可.示例如下:

cl.php

Copy after login

ts.php

Copy after login

运行结果:

8404b87b069498571171d465e02d697.png

更多相关知识,请访问PHP中文网

Related labels:
php
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
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!