Home >Backend Development >PHP Tutorial >set_include_path和require,include

set_include_path和require,include

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:07:29941browse

在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:

// 包含配置文件和函数库路径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版本,对现在来说两者没有差别。

Statement:
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