国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php關(guān)于require和include的區(qū)別

2024-05-04 21:57:58
字體:
供稿:網(wǎng)友

include() 或 require() 函數(shù),您可以在服務(wù)器執(zhí)行 PHP 文件之前在該文件中插入一個(gè)文件的內(nèi)容,除了它們處理錯(cuò)誤的方式不同之外,這兩個(gè)函數(shù)在其他方面都是相同的.

include() 或 require() 函數(shù),您可以在服務(wù)器執(zhí)行 php 文件之前在該文件中插入一個(gè)文件的內(nèi)容,除了它們處理錯(cuò)誤的方式不同之外,這兩個(gè)函數(shù)在其他方面都是相同的,include() 函數(shù)會(huì)生成一個(gè)警告(但是腳本會(huì)繼續(xù)執(zhí)行),而 require() 函數(shù)會(huì)生成一個(gè)致命錯(cuò)誤(fatal error)(在錯(cuò)誤發(fā)生后腳本會(huì)停止執(zhí)行).

  1. <html> 
  2. <body> 
  3. <?php include("header.php"); ?> 
  4. <h1>welcome to my home page</h1> 
  5. <p>some text</p> 
  6. </body> 
  7. </html> 

三個(gè)文件,"default.php"、"about.php" 以及 "contact.php" 都引用了 "menu.php" 文件,這是 "default.php" 中的代碼:

  1. <?php include("menu.php"); ?> 
  2. <h1>welcome to my home page</h1> 
  3. <p>some text</p> 
  4. </body> 
  5. </html> 

require() 函數(shù)

require() 函數(shù)與 include() 相同,不同的是它對(duì)錯(cuò)誤的處理方式.

include() 函數(shù)會(huì)生成一個(gè)警告(但是腳本會(huì)繼續(xù)執(zhí)行),而 require() 函數(shù)會(huì)生成一個(gè)致命錯(cuò)誤(fatal error)(在錯(cuò)誤發(fā)生后腳本會(huì)停止執(zhí)行).

如果在您通過 include() 引用文件時(shí)發(fā)生了錯(cuò)誤,會(huì)得到類似下面這樣的錯(cuò)誤消息:

  1. <html> 
  2. <body> 
  3. <?php 
  4. include("wrongfile.php"); 
  5. echo "hello world!"
  6. ?> 
  7. </body> 
  8. </html> 

錯(cuò)誤消息:

warning: include(wrongfile.php) [function.include]:
failed to open stream:
no such file or directory in c:homewebsitetest.php on line 5
 
warning: include() [function.include]:
failed opening 'wrongfile.php' for inclusion
(include_path='.;c:php5pear')
in c:homewebsitetest.php on line 5
 
hello world!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 柳江县| 高邑县| 连平县| 雷州市| 醴陵市| 西安市| 鄂温| 广宗县| 自治县| 武义县| 隆昌县| 玉田县| 汉中市| 临洮县| 论坛| 石柱| 施甸县| 闽清县| 马公市| 民权县| 黔江区| 花莲县| 台山市| 安顺市| 延寿县| 宜章县| 灵武市| 太仓市| 康平县| 罗田县| 屏东县| 延安市| 女性| 古蔺县| 蒲江县| 崇文区| 于都县| 资中县| 宜良县| 海兴县| 建湖县|