hjkn 发表于 2015-8-29 13:41:49

php 非常有用的高级函数PATH_SEPARATOR常量和set_include_path

  zendframework的示例index.php里有这样一句

set_include_path('.' . PATH_SEPARATOR . '../library/'. PATH_SEPARATOR . './application/models/'. PATH_SEPARATOR . './application/lib/'. PATH_SEPARATOR . get_include_path());  不知道 PATH_SEPARATOR是什么,其实就是一个常量
  直接echo就知道它的值了,在linux上是一个":"号,WIN上是一个";"号
  set_include_path就是设置php的包含文件路径,相当是操作系统的环境变量

<?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)


参数描述

path
必需。规定要检查的路径。


process_sections
  可选。规定要返回的数组元素。默认是 all。
  可能的值:


[*]PATHINFO_DIRNAME - 只返回 dirname
[*]PATHINFO_BASENAME - 只返回 basename
[*]PATHINFO_EXTENSION - 只返回 extension





说明
  pathinfo() 返回一个关联数组包含有 path 的信息。
  包括以下的数组元素:


[*]
[*]
[*]



提示和注释

注释:如果不是要求取得所有单元,则 pathinfo() 函数返回字符串。



例子

例子 1

<?php
print_r(pathinfo("/testweb/test.txt"));
?>
  输出:

Array
(
=> /testweb
=> test.txt
=> 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");
  }
页: [1]
查看完整版本: php 非常有用的高级函数PATH_SEPARATOR常量和set_include_path