PHP中include_path
来源:互联网 发布:淘宝卖家进货app用什么 编辑:程序博客网 时间:2024/04/28 18:07
include_path是PHP中的一个环境变量,在php.ini中初始化设置
例如:有些如下的文件
test/a.phptest/b.phptest/test2/c.phptest/test2/d.php
如果没有设置include_path变量,index.php需要这样写:
<?php include_once 'test/a.php'; include_once 'test/b.php'; include_once 'test/test2/c.php'; include_once 'test/test2/d.php';?>
使用上面的引用方式,引用路径比较长,当引用目录位置改变时需要修改大量代码。使用include_path可以简化上述问题
PATH_SEPARATOR是一个常量,在Linux系、Mac系统是一个”:”,
在Windlows上是一个”;”号。
<?php set_include_path("test".PATH+SEPARATOR."test/test2"); include_once 'a.php'; include_once 'b.php'; include_once 'c.php'; include_once 'd.php';?>
include_path是PHP的环境变量,因而可以在php.ini设置,每次请求时include_path都会被PHP用php.ini中的值初始化。也可以用代码的方式修改include_path值,不过,修改后结果在请求完毕后会自动丢弃,不会带到下一个请求。因此,每次请求时需要重新设置。
在代码中获取和设置include_path值有如下两种方式:
方式一:ini_get()和ini_set()方式,此种方式使用于所有PHP版本。
<?php $s = ini_get('include_path'); ini_set($s . PATH_SEPARATOR . 'test'.PATH_SEPARATOR . 'test/test2'); ?>
方式二:get_include_path()和set_include_path()方式,此种方式使用于PHP4.3以后的版本。
<?php $s = get_include_path(); set_include_path($s . PATH_SEPARATOR . 'test'.PATH_SEPARATOR . 'test/test2'); ?>
0 0
- PHP中include_path
- php.ini中include_path用处
- php include_path
- php中遇到include_path='.;C:\php5\pear'的错误
- php中 include_path='.;c:php5pear'的错误解决
- Php中include_path='.;C:\php5\pear'错误
- php include_path设置
- php include_path设置
- PHP include_path 分析
- PHP include_path设置
- PHP include_path 设置
- php--配置指令include_path
- PHP include_path设置
- 如何设置php的include_path
- PHP - 获取和设置include_path
- PHP include_path设置技巧分享
- PHP include_path设置技巧分享
- include_path
- redis技术之旅二
- js 复制网页内容,兼容各浏览器
- hdu 5387
- mysql关键字
- 什么是 HTML?
- PHP中include_path
- OpenMANO初探
- 2016校招华为机试题目回忆1
- VC++获取病毒的消息钩子
- iOS概念入门学习-C语言-指针
- iOS_UITableView 编辑(cell的插入, 删除, 移动)
- Python中range和xrange的异同之处
- POJ 1321----棋盘问题(dfs+回溯)
- 10盏灯初始状态为暗,一个人顺次按动开关,每走一次后少按一盏灯,求最后10盏灯的状态