首頁  >  文章  >  後端開發  >  php 非常有用的高階函數PATH_SEPARATOR常數和set_include_path

php 非常有用的高階函數PATH_SEPARATOR常數和set_include_path

WBOY
WBOY原創
2016-08-08 09:29:131071瀏覽
zendframework的範例index.php裡面有這樣一句話 set_include_path('.' . PATH_SEPARATOR . '../library/'. PATH_SEPARATOR . './application/models/'. PATH_SEPARATOR . './application/lib/'. PATH_SEPARATOR . get_include_path();其實就是一個常數直接echo就知道它的值了,在linux上是一個":"號,WIN上是一個";"號set_include_path就是設定php的包含檔路徑,相當是作業系統的環境變項 // Works as of PHP 4.3.0set_include_path('/inc'); // Works in all PHP versionsini_set('include_path', '/inc');?> 關於set_include_path的問題,在win下,當你要include多個路徑的話,你要用";"隔開,但在linux下就使用":"隔開的。 所以上面的zf的程式碼真是絕配.get_include_path取得目前已有的環境變數
定義和用法

pathinfo() 函數以陣列的形式傳回檔案路徑的資訊。

語法

pathinfo(path,options)

參數pathprocess_sections可選。規定要傳回的數組元素。預設是 all。 [dirname]
描述
必需。規定要檢查的路徑。

可能的值:

PATHINFO_DIRNAME - 只回傳dirname
  • PATHINFO_BASENAME - 只回傳basename
  • PATHINFO_EXTENSION -說明() 傳回一個關聯數組包含有 
  • path
  • 的訊息。
包含以下的陣列元素:

[basename]

[extension]

提示與註解
    )註解串。
  • 例子
  • 例子1
<?php
print_r(pathinfo("/testweb/test.txt"));
?>
輸出:
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)

範例2

<?php
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
?>

輸出:

test.txt
TORSm

 

路徑分隔符號

windows or / linux

/ function __autoload($classname){  if(preg_match('/\\/',$classname)){    約else{        $path = str_replace('_',DIRECTORY_SEPARATOR,$classname);    }轉載自:http:// www.cnblogs.com/jackluo/archive/2013/04/09/3010257.html 以上就介紹了php 非常有用的高階函數PATH_SEPARATOR常數和set_include_path,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn