php 非常有用的高级函数PATH_SEPARATOR常量和set_include_path 3ff8
2017-11-02 20:38
471 查看
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 的信息。包括以下的数组元素:
[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 | / |
if(preg_match('/\\\\/',$classname)){
$path = str_repace('\\',DIRECTORY_SEPARATOR,$classname);
}else{
$path = str_replace('_',DIRECTORY_SEPARATOR,$classname);
}
require_once("$path.php");
}
相关文章推荐
- php 非常有用的高级函数PATH_SEPARATOR常量和set_include_path
- PHP中set_include_path()函数相关用法分析
- PHP中set_include_path()函数相关用法分析
- PHP 函数: set_include_path
- PHP中set_include_path()函数相关用法分析
- 关于PHP的set_include_path()函数
- include("include_path")函数包含路径详讲__PHP_include()
- 解析PHP中DIRECTORY_SEPARATOR,PATH_SEPARATOR两个常量的作用
- 【转】PHP里10个鲜为人知但却非常有用的函数
- PHP中10个不常见却非常有用的函数
- PHP一些非常有用的函数
- PHP里10个鲜为人知但却非常有用的函数
- PHP里10个鲜为人知但却非常有用的函数
- PHP里10个鲜为人知但却非常有用的函数
- PHP的DIRECTORY_SEPARATOR,PATH_SEPARATOR两个常量的作用
- PHP一些非常有用的函数
- php中的路径问题与set_include_path
- php常量DIRECTORY_SEPARATOR和PATH_SEPARATOR
- php中的路径问题与set_include_path使用介绍