PHP中 require() 和 include() 的区别
PHP require()函数: PHP中的 require( )函数主要用于将一个PHP文件的内容/代码/数据包含到另一个PHP文件中。在此过程中,如果出现任何类型的错误,则此require()函数将弹出警告以及致命错误,并立即停止脚本的执行。为了使用这个require()函数,我们首先需要创建两个PHP文件。使用include()函数,将一个PHP文件包含到另一个文件中。之后,您将看到两个PHP文件合并为一个 HTML 文件。
示例 1:
HTML
Welcome to geeks for geeks!
Myself, Gaurav Gandal
Thank you
GFG.php
visit Again-" . date("Y") . " geeks for geeks.com
";
?>
HTML
Welcome to geeks for geeks!
Myself, Gaurav Gandal
Thank you
GFG.php
Visit Again; " . date("Y") . " Geeks for geeks.com
";
?>
GFG。 PHP
visit Again-" . date("Y") . " geeks for geeks.com
";
?>
输出:
PHP包含()函数: PHP中的include()函数主要用于将一个PHP文件的内容/代码/数据包含到另一个PHP文件中。在此过程中,如果出现任何类型的错误,则此include()函数将弹出警告,但与require()函数不同,它不会停止脚本的执行,而是脚本将继续其进程。为了使用这个include()函数,我们首先需要创建两个PHP文件。使用include()函数,将一个PHP文件包含到另一个文件中。之后,您将看到两个PHP文件合并为一个 HTML 文件。
示例 2 :
HTML
Welcome to geeks for geeks!
Myself, Gaurav Gandal
Thank you
GFG。 PHP
Visit Again; " . date("Y") . " Geeks for geeks.com
";
?>
输出:
require() 和 include() 的区别: include() require() The include() function does not stop the execution of the script even if any error occurs. The require() function will stop the execution of the script when an error occurs. The include() function does not give a fatal error. The require() function gives a fatal error The include() function is mostly used when the file is not required and the application should continue to execute its process when the file is not found. The require() function is mostly used when the file is mandatory for the application. The include() function will only produce a warning (E_WARNING) and the script will continue to execute. The require() will produce a fatal error (E_COMPILE_ERROR) along with the warning.