php中的路徑問題與set_include_path使用介紹
更新時間:2014年02月11日 17:00:22 作者:
這篇文章主要介紹了php中的路徑問題與set_include_path,需要的朋友可以參考下
first:
php中常用的路徑
當前文件路徑:D:\phpweb\php_example\include_path.php
1.dirname(__FILE__); //輸出D:\phpweb\php_example
2.$_SERVER['SCRIPT_FILENAME']; //輸出D:/phpweb/php_example/include_path.php
second:
php中的set_include_path
在php中,include文件時,當包含路徑不為相對也不為絕對時(如:include("example.php")),會先查找include_path所設(shè)置的目錄,然后再在當前目錄查找,這也是為什么很多資料上提到include("./example.php")比include("example.php")效率高的原因。
方法:
1.ini_set("include_path", "/usr/lib/pear"); //所有版本
2.set_include_path("/usr/lib/pear"); //version>=4.3.0
可以用下面的方法,在原有目錄上添加目錄
<?php
$path = '/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);//設(shè)置后的include_path變?yōu)轭愃?usr/lib/function;/usr/lib/pear
?>
php中常用的路徑
當前文件路徑:D:\phpweb\php_example\include_path.php
復(fù)制代碼 代碼如下:
1.dirname(__FILE__); //輸出D:\phpweb\php_example
2.$_SERVER['SCRIPT_FILENAME']; //輸出D:/phpweb/php_example/include_path.php
second:
php中的set_include_path
在php中,include文件時,當包含路徑不為相對也不為絕對時(如:include("example.php")),會先查找include_path所設(shè)置的目錄,然后再在當前目錄查找,這也是為什么很多資料上提到include("./example.php")比include("example.php")效率高的原因。
方法:
1.ini_set("include_path", "/usr/lib/pear"); //所有版本
2.set_include_path("/usr/lib/pear"); //version>=4.3.0
可以用下面的方法,在原有目錄上添加目錄
復(fù)制代碼 代碼如下:
<?php
$path = '/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);//設(shè)置后的include_path變?yōu)轭愃?usr/lib/function;/usr/lib/pear
?>
相關(guān)文章
PHP面向?qū)ο蟪绦蛟O(shè)計重載(overloading)操作詳解
這篇文章主要介紹了PHP面向?qū)ο蟪绦蛟O(shè)計重載(overloading)操作,結(jié)合實例形式詳細分析了php面向?qū)ο蟪绦蛟O(shè)計重載原理、實現(xiàn)方法及相關(guān)操作技巧,需要的朋友可以參考下2019-06-06
php+mysql+ajax實現(xiàn)單表多字段多關(guān)鍵詞查詢的方法
這篇文章主要介紹了php+mysql+ajax實現(xiàn)單表多字段多關(guān)鍵詞查詢的方法,涉及php基于ajax的數(shù)據(jù)庫查詢、表格操作等相關(guān)技巧,需要的朋友可以參考下2017-04-04
PHP接收json 并將接收數(shù)據(jù)插入數(shù)據(jù)庫的實現(xiàn)代碼
這篇文章主要介紹了PHP接收json 并將接收數(shù)據(jù)插入數(shù)據(jù)庫的實現(xiàn)代碼,需要的朋友可以參考下2015-12-12
PHP基于自定義函數(shù)實現(xiàn)的漢字轉(zhuǎn)拼音功能實例
這篇文章主要介紹了PHP基于自定義函數(shù)實現(xiàn)的漢字轉(zhuǎn)拼音功能,涉及php表單及字符串編碼轉(zhuǎn)換、遍歷等相關(guān)操作技巧,需要的朋友可以參考下2017-09-09

