search
Homephp教程php手册PHP include_path设置技巧分享

PHP include_path设置技巧分享

Jun 13, 2016 pm 12:08 PM
includepathphpfunctionsharesignificanceSkillofset up

1.include_path的意义

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

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


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.