php 很是有用的高級函數PATH_SEPARATOR常量和set_include_path

php 很是有用的高級函數PATH_SEPARATOR常量和set_include_path

zendframework的示例index.php裏有這樣一句php

 set_include_path('.' . PATH_SEPARATOR . '../library/'. PATH_SEPARATOR . './application/models/'. PATH_SEPARATOR . './application/lib/'. PATH_SEPARATOR . get_include_path()); html

不知道 PATH_SEPARATOR是什麼,其實就是一個常量linux

直接echo就知道它的值了,在linux上是一個":"號,WIN上是一個";"號web

set_include_path就是設置php的包含文件路徑,至關是操做系統的環境變量windows

 <?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下就使用":"隔開的。app

因此上面的zf的代碼真是絕配.
get_include_path取得當前已有的環境變量函數

定義和用法

pathinfo() 函數以數組的形式返回文件路徑的信息。ui

語法

pathinfo(path,options)
參數 描述
path 必需。規定要檢查的路徑。
process_sections

可選。規定要返回的數組元素。默認是 all。spa

可能的值:

  • PATHINFO_DIRNAME - 只返回 dirname
  • PATHINFO_BASENAME - 只返回 basename
  • PATHINFO_EXTENSION - 只返回 extension

說明

pathinfo() 返回一個關聯數組包含有 path 的信息。

包括如下的數組元素:

  • [dirname]
  • [basename]
  • [extension]

提示和註釋

註釋:若是不是要求取得全部單元,則 pathinfo() 函數返回字符串。

例子

例子 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

 DIRECTORY_SEPARATOR   window 下面

說明

 

路徑分隔符

windows

\ or /

linux

/

 

function __autoload($classname){

  if(preg_match('/\\\\/',$classname)){

    $path = str_repace('\\',DIRECTORY_SEPARATOR,$classname);

      }else{

       $path = str_replace('_',DIRECTORY_SEPARATOR,$classname);

     }

   require_once("$path.php");

}

相關文章
相關標籤/搜索