當前位置:編程學習大全網 - 網站源碼 - 某個php文件如何調用其他文件夾下php文件 如:我想在index.php中調用 ad文件夾下的foot.php 如何寫謝謝!

某個php文件如何調用其他文件夾下php文件 如:我想在index.php中調用 ad文件夾下的foot.php 如何寫謝謝!

請使用include_once “ad/foot.php”(只引用壹次)

調用其它php文件有多種方式:require ,require_once ,include ,include_once 但include 和require是有區別的:

require 這個函式通常放在 PHP 程式的最前面,PHP 程式在執行前,就會先讀入 require 所指定引入的檔案,使它變成 PHP 程式網頁的壹部份。常用的函式,亦可以這個方法將它引入網頁中。

include這個函式壹般是放在流程控制的處理區段中。PHP 程式網頁在讀到 include 的檔案時,才將它讀進來。這種方式,可以把程式執行時的流程簡單化。

還有,使用require函數引用文件是不受任何條件限制壹定會被讀取到當前php頁的,例如

$language = 'english';

if $language = "french" {

include_once '.\french_file.php';

}

else {

include_once '.\not_french_file.php';

}

此時,因為條件語句的關系,只引用了not_french_file.php。

而如果用require代替include

if $language = "french" {

require_once '.\french_file.php'

}

else {

require_once '.\not_french_file.php'

}

無論條件語句如何,french_file.php和not_french_file.php都會被調用到當前頁面。

  • 上一篇:bias指標詳解
  • 下一篇:第三方加大華錄像機是什麽協議?
  • copyright 2024編程學習大全網