set_include_path, get_include_path
2012-09-12 17:06
323 查看
set_include_path
最近set_include_path, get_include_path老在我眼前晃悠,一直都没弄懂这玩意儿是怎么玩的。看了一些网上资料后,就茅塞顿开了。
set_include_path是为include和require等文件包含函数用的。
例如:projectName/home/Action/lib,在这个目录下有如下文件:a.php, b.php..........如果我们想在其他文件中包含这些文件时,我们可以这样写
set_include_path('projectName/home/Action/lib');
require('a.php');
当指定一个目录为include_path时,但是当lib目录下找不到所要求包含的文件,而在当前页面目录下正好存在这个名称的文件时,则转为包含当前目录下的该文件。
当指定了多个目录为 include_path ,而所要求包含的文件在这几个目录都有相同名称的文件存在时,php选择使用设定 include_path 时排位居前的目录下的文件。不同路径之间用PHP常量PATH_SEPARATOR来分割。在类unix的系统中,PATH_SEPARATOR是 ":";在windows系统中,PATH_SEPARATOR的值是";";
get_include_path
获取当前include_path 的值,也可以输出include_path,查看当前的包含路径。
string dirname ( string path )
假如你的首页中用到了_FILE_这个变量:
(假设你的网页所在目录为:http://localhost/web/index.php),那么:
_FILE_的值为http://localhost/web/index.php(一个绝对路径)。而此时dirname (_FILE_)表示的就是http://localhost/web/也就是没有index.php这个文件名。
而dirname(dirname(_FILE_))表示的就是上一级的目录,以此类推;
最近set_include_path, get_include_path老在我眼前晃悠,一直都没弄懂这玩意儿是怎么玩的。看了一些网上资料后,就茅塞顿开了。
set_include_path是为include和require等文件包含函数用的。
例如:projectName/home/Action/lib,在这个目录下有如下文件:a.php, b.php..........如果我们想在其他文件中包含这些文件时,我们可以这样写
set_include_path('projectName/home/Action/lib');
require('a.php');
当指定一个目录为include_path时,但是当lib目录下找不到所要求包含的文件,而在当前页面目录下正好存在这个名称的文件时,则转为包含当前目录下的该文件。
当指定了多个目录为 include_path ,而所要求包含的文件在这几个目录都有相同名称的文件存在时,php选择使用设定 include_path 时排位居前的目录下的文件。不同路径之间用PHP常量PATH_SEPARATOR来分割。在类unix的系统中,PATH_SEPARATOR是 ":";在windows系统中,PATH_SEPARATOR的值是";";
get_include_path
获取当前include_path 的值,也可以输出include_path,查看当前的包含路径。
string dirname ( string path )
假如你的首页中用到了_FILE_这个变量:
(假设你的网页所在目录为:http://localhost/web/index.php),那么:
_FILE_的值为http://localhost/web/index.php(一个绝对路径)。而此时dirname (_FILE_)表示的就是http://localhost/web/也就是没有index.php这个文件名。
而dirname(dirname(_FILE_))表示的就是上一级的目录,以此类推;
相关文章推荐
- set_include_path和get_include_path使用及注意事项
- 关于get_include_path()和set_include_path()
- set_include_path和get_include_path用法详解
- 设置include和require的目录get_include_path与set_include_path
- set_include_path和get_include_path用法详解
- php手记-set_include_path和get_include_path用法详解
- set_include_path和get_include_path用法详解
- set_include_path和get_include_path用法详解
- set_include_path和get_include_path使用及注意事项
- 【php】set_include_path和get_include_path用法详解
- set_include_path & get_include_path
- PHP--set_include_path和get_include_path用法详解
- php get_include_path();是干嘛的、??还有set_include_path();/?????
- php 文件路径设置 set_include_path(); get_include_path();
- set_include_path get_include_path
- set_include_path和get_incl…
- set_include_path, get_include_path 使用
- set_include_path和get_include_path用法详解
- set_include_path和get_include_path用法详解
- php的set_include_path与get_include_path()的用法