php的set_include_path函數

來源:互聯網
上載者:User
php的set_include_path函數,是用來設定應用程式目錄的,開發項目時合理應用此函數, 可以讓我們在include時不用一層一層的計算目錄,還可以提高我們開發的效率,減少檔案包含錯誤率,給我們 PHP項目帶來了簡便。 PHP基礎較差的同學們更要好好的看看了。

看個例子

建立2個php檔案,一個目錄位置結構如下

/index.php

/include/config.php

index.php Code:

<?php  set_include_path("include");  include("config.php");   ?>

/include/config.php Code:

<?php  set_include_path("include");  include("config.php");   ?>


現在我們運行index.php 怎麼樣,看到結果沒,我們include時只用寫config.php就可以把/inlcude/config.php 檔案包含進來.

設定多個include目錄時用 " ;" 號分開。如: set_include_path("include;include2;include3;lib;c:/php/lib");可以用相對路徑也可以用相對路徑. 或許這段小小的代碼你可能感覺不出set_include_path的好處,不過不要緊,你只要記住這麼個代碼可以實現這樣的功能即可,在你以後技 術提上去,開時開發大型項目時不要忘了有這麼個函數,他可以減少你的工作量.

姐妹函數get_include_path() 可以擷取當時的include目錄, 實現set_include_path同樣功能的還有我們強大又可愛的ini_set() 用法:

ini_set('include_path', '目錄名');

相關推薦:

set_include_path用法

set_include_path和get_include_path用法詳解

set_include_path在win和linux下的區別_PHP教程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.