Home > php教程 > PHP源码 > php中set_include_path和require,include介绍

php中set_include_path和require,include介绍

WBOY
Release: 2016-06-08 17:19:36
Original
1075 people have browsed it

在php中set_include_path会导致require,include用法不一样了,对于这个问题我们来看一个简单的例子,具体如下。

<script>ec(2);</script>

在PHP中经常使用include,require来引用其他文件,使用相对路径或者绝对路径,如果通过set_include_path函数或者ini_set(‘include_path’,xxx)设置include_path配置选项,那么require文件如果在其他目录也可以直接引用。

设置include_path配置选项

如:require_once “class.smarttemplate.php”,这个文件其实并不在当前文件所在目录,但是同样可以这样直接引用。因为前面通过ini_set设置了include_path:

PHP

// 包含配置文件和函数库路径
ini_set('include_path', INCLUDE_PATH . DS . "library" . PATH_SEPARATOR . ini_get('include_path'));


set_include_path函数

set_include_path函数和ini_set(‘include_pah’,xxx)作用是一样的,只不过ini_set方式适合所有PHP版本,对现在来说两者没有差别。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template