Heim  >  Artikel  >  Backend-Entwicklung  >  PHP include_path设置技巧分享_PHP教程

PHP include_path设置技巧分享_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:27:421522Durchsuche

1.include_path的意义

当时候函数include(),require(),fopen_with_path()函数来寻找文件时候.在不设置include_path的情况下,这些函数打开文件时候默认的是以web根目录去寻找.当设置include_path以后,这些php函数就会先在指定的include_path目录下面去搜索寻找.

其原理和window系统的环境变量相似,在window运行cmd命令的时候,输入一些cmd的命令之后系统会在其设定的环境变量里面去搜索这些命令是否存在,存在就可以执行.
PHP include_path设置技巧分享_PHP教程

2.include_path的设置
第一种方法:

修改php.ini文件中的include_path项。

include_path = .:/usr/local/lib/php:./include
第二个方法:

使用ini_set方法。
ini_set("include_path", ".:../:./include:../include");     

3.注意
zendframework include 设置 index.php

复制代码 代码如下:

set_include_path('.' .PATH_SEPARATOR.'../library/'
.PATH_SEPARATOR.'./application/models/'
.PATH_SEPARATOR.'./application/lib/'
.PATH_SEPARATOR.get_include_path());

PATH_SEPARATOR是一个常量,在Linux系统中是一个" : "号,Windows上是一个";"号。

所以编写程序时最好用常量 PATH_SEPARATOR 代替,否则如果系统从linux移植到win系统或反过来移植会出错!
get_include_path取得当前已有的环境变量,加上前面的设置就是新的系统include

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/323708.htmlTechArticle1.include_path的意义 当时候函数include(),require(),fopen_with_path()函数来寻找文件时候.在不设置include_path的情况下,这些函数打开文件时候默认的是...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn