php手记-set_include_path和get_include_path用法详解
2015-11-27 15:06
846 查看
set_include_path
先看效果//假如有段代码是这样的: include("123/test1.php"); include("123/test2.php"); include("456/test3.php"); require("123/test4.php"); require("123/test5.php"); //现在要把123的目录换了换成567,这下是不是要搬砖了,要改的地方很多,如果在其他php文件里也引用了123目录下的php那就更麻烦了 //再看下面的代码 是不是感觉好很多 set_include_path("123"); include("test1.php"); include("test2.php"); include("test3.php"); require("test4.php"); require("test5.php"); //在进一步 设置一下 456 set_include_path("123:456");//路径间用:隔开,也可以用PATH_SEPARATOR代替:,如set_include_path("123".PATH_SEPARATOR."456") include("test1.php"); include("test2.php"); include("test3.php"); require("test4.php"); require("test5.php"); //如果123、456目录下都有test1.php,那么那么那个路径在前就使用其下的test1.php,那么上例中使用的肯定是123/test1.php了
作用:
简化文件的管理
get_include_path
作用获取当前的 include_path 配置选项
例子
set_include_path("test2:test1:test3"); echo get_include_path(); //output:test2:test1:test3
因此在set_include_path时需要用get_include_path获得之前设定的path(可以是用set_include_path设定 或者在php.ini里面设定的)拼到要设定的路径的前面,避免把被人或系统设定的path替换掉如:
//别人设定的 other.php set_include_path("test2:test1:test3"); echo get_include_path();//output:test2:test1:test3 // my.php set_include_path(get_include_path().PATH_SEPARATOR."test4:test5:test6"); echo get_include_path();//output:test2:test1:test3:test4:test5:test6
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法
- 安装Apache和PHP的一些补充
- Linux Apache+MySQL+PHP
- 建立Apache+PHP+MySQL数据库驱动的动态网站
- PHP 5.3.0 安装分析心得
- apache 环境下 php 的配置注意事项
- ASP.NET、ASP、PHP、JSP之间有什么区别?
- PHP VBS JS 函数 对照表
- C语言实现的统计php代码行数功能源码(支持文件夹、多目录)
- php xml 入门学习资料