亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

set_include_path()和get_include_path() 這個兩個方法怎么用???

老師能不能詳細講解下set_include_path()和get_include_path() 這個兩個方法怎么用啊?PATH_SEPARATOR是什么,百度了一天了都看不懂,這方面的學習資料好少啊

正在回答

1 回答

先跟你解釋下 include_path是包含路徑的意思,也就是說如果你設置了包含路徑,那么在include( )或者require()時會優先在你設置的路徑下尋找文件,如果沒有設置,那么就必須在include()或者require()時在( )里面寫“路徑/文件名”,所以如果經常要用include()或者require()函數的話,為了避免每次都寫“路徑/文件名”,我就先設置好包含路徑,這樣就不要每次都寫了;

那么怎么設置包含路徑呢,當然是用set_include_path()了;

同理,get_include_path()就是獲得包含路徑的意思。

PATH_SEPARATOR是路徑分隔符,在window下用分號表示。

下面結合老師的例子分析:

<?php
header("content-type:text/html;charset=utf-8");
session_start();
define('ROOT',?dirname(__FILE__));
set_include_path('.'.PATH_SEPARATOR.ROOT.'/lib'.PATH_SEPARATOR.ROOT.'/configs'.PATH_SEPARATOR.ROOT.'/core'.PATH_SEPARATOR.get_include_path());
echo?'.'.PATH_SEPARATOR.ROOT.'/lib'.PATH_SEPARATOR.ROOT.'/configs'.PATH_SEPARATOR.ROOT.'/core'.PATH_SEPARATOR.get_include_path();
//下面就是用set_include_path()設置的包含路徑,我把它echo出來了:
//.;D:\wamp\www\shopImooc1\shopImooc/lib;D:\wamp\www\shopImooc1\shopImooc/configs;D:\wamp\www\shopImooc1\shopImooc/core;.;D:\wamp\www\shopImooc1\shopImooc/lib;D:\wamp\www\shopImooc1\shopImooc/configs;D:\wamp\www\shopImooc1\shopImooc/core;.;C:\php\pear
echo?"<hr>";
echo?get_include_path();
//這是get_include_path()的路徑,如下:
//.;D:\wamp\www\shopImooc1\shopImooc/lib;D:\wamp\www\shopImooc1\shopImooc/configs;D:\wamp\www\shopImooc1\shopImooc/core;.;C:\php\pear
require_once?'string.func.php';
require_once?'image.func.php';
require_once?'upload.func.php';
require_once?'page.func.php';
require_once?'mysql.func.php';
require_once?'common.func.php';
require_once?'configs.php';
require_once?'admin.inc.php';
require_once?'cate.inc.php';
connect();

注意看我上面代碼里的注釋,你也可以自己打印出來看看。在set_include_path( )里,最好把get_include_path寫在前面,像這樣:set_include_path(get_include_path().PATH_SEPARATOR . ROOT.'/core');

.;D:\wamp\www\shopImooc1\shopImooc/lib;D:\wamp\www\shopImooc1\shopImooc/configs;D:\wamp\www\shopImooc1\shopImooc/core;.;C:\php\pear?? ----------------------------這段路徑里黑體的分號就叫: PATH_SEPARATOR?? ?????? . ;C:\php\pear是php默認的include_path

PS: 說的有點啰嗦,不知道說清楚了沒有,O(∩_∩)O哈哈~




4 回復 有任何疑惑可以回復我~
#1

superhuman進化中 提問者

非常感謝!
2016-11-06 回復 有任何疑惑可以回復我~
#2

一畝地

不客氣!
2016-11-08 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
手把手教你實現電商網站后臺開發
  • 參與學習       117255    人
  • 解答問題       2101    個

手把手教你用PHP搭建電子商務平臺,由淺入深教你搭建電商系統

進入課程

set_include_path()和get_include_path() 這個兩個方法怎么用啊?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號