php的set_include_path与get_include_path()的用法
来源:互联网 发布:js工厂方法 编辑:程序博客网 时间:2024/05/01 12:35
php中set_include_path函数用法:
php中的set_include_path函数可用于设置应用程序目录,开发项目时合理应用这些函数,不但可以让我们在include时不用一层一层的计算目录,还可以提高我们开发的效率,减少文件包含错误率.
例如:
简历2个php文件,一个目录
位置结构如下
/index.php
/include/config.php
index.php:
<?php
set_include_path("include");
include("config.php");
?>
/include/config.php
以下为引用的内容:
我是include下的config.php
现在我们运行index.php
怎么样,看到结果没
我们include时只用写config.php就可以把/inlcude/config.php 文件包含进来
设定多个include目录时用 " ;" 号分开
如: set_include_path("include;include2;include3;lib;c:\php\lib");
可以用相对路径也可以用绝对路径.
或许这段小小的代码你可能感觉不出set_include_path的好处,不过不要紧,你只要记住这么个代码可以实现这样的功能即可,在你以后技术提上去,开始开发大型项目时不要忘了有这么个函数,他可以减少你的工作量.
姐妹函数get_include_path() 可以获取当时的include目录,
实现set_include_path同样功能的还有我们强大又可爱的ini_set()
用法:
php中的set_include_path函数可用于设置应用程序目录,开发项目时合理应用这些函数,不但可以让我们在include时不用一层一层的计算目录,还可以提高我们开发的效率,减少文件包含错误率.
例如:
简历2个php文件,一个目录
位置结构如下
/index.php
/include/config.php
index.php:
<?php
set_include_path("include");
include("config.php");
?>
/include/config.php
以下为引用的内容:
我是include下的config.php
现在我们运行index.php
怎么样,看到结果没
我们include时只用写config.php就可以把/inlcude/config.php 文件包含进来
设定多个include目录时用 " ;" 号分开
如: set_include_path("include;include2;include3;lib;c:\php\lib");
可以用相对路径也可以用绝对路径.
或许这段小小的代码你可能感觉不出set_include_path的好处,不过不要紧,你只要记住这么个代码可以实现这样的功能即可,在你以后技术提上去,开始开发大型项目时不要忘了有这么个函数,他可以减少你的工作量.
姐妹函数get_include_path() 可以获取当时的include目录,
实现set_include_path同样功能的还有我们强大又可爱的ini_set()
用法:
ini_set('include_path', '目录名');
set_include_path() 函数可以在php程序中动态改变php的include_path参数,其参数是一个字符串,多个不同的目录可以串联在一起作为一个参数一起提交——不同的目录间使用目录分割符号分开,在类unix的系统中这个分隔符是“:”,在windows系统中这个分隔符是“;”,所以php
提供一个常量 PATH_SEPARATOR 来表示当前系统中的这个分隔符。
include_path 的规则如下:
# 当只指定了一个目录为 include_path ,比如 set_include_path("class")。class 为php包含文件的默认起点,但是当class目录下找不到所要求包含的文件,而在当前页面目录下正好存在这个名称的文件时,则转为包含当前目录下的该文件。
# 当指定了多个目录为 include_path ,而所要求包含的文件在这几个目录都有相同名称的文件存在时,php选择使用设定 include_path 时排位居前的目录下的文件。
- php的set_include_path与get_include_path()的用法
- php手记-set_include_path和get_include_path用法详解
- PHP--set_include_path和get_include_path用法详解
- 设置include和require的目录get_include_path与set_include_path
- set_include_path()与get_include_path()
- set_include_path和get_include_path用法详解
- set_include_path和get_include_path用法详解
- set_include_path和get_include_path用法详解
- set_include_path和get_include_path用法详解
- 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函数的用法
- set_include_path & get_include_path
- set_include_path()的用法
- php的set_include_path函数
- PHP的set_include_path函数
- POJ-1040
- Windows Storage Server 2008 R2 下载安装
- Linux下分区详解之--Fdisk
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- G-Sockets(IOCP) 2.5 Demo 源码 (VC2008 & Delphi7/2010)下载
- php的set_include_path与get_include_path()的用法
- 线性表基础知识(一)
- 改变WP7程序启动的页面Page.xaml
- Myeclipse 6.0.1下载,支持eclipse3.3.1
- eclipse 中的Web project与 Myeclipse 中的 web project有何区别?
- hibernate 三 多对一
- android UI进阶之用ViewPager实现欢迎引导页面
- 让默认安装的Linux支持中文
- DIRECTORY_SEPARATOR和PATH_SEPARATOR的用法