Php函数set_include_path()函数详解

set_include_path——设置include_path配置选项。

说明

string set_include_path(string $new_include_path);
为当前脚本设置include_path运行时的配置选项。

参数

new\_include\_path
    include\_path新的值。

返回值

成功时返回旧的include_path或者在失败时返回FALSE.

范例

Example 1

<?php
//自PHP4.3.0起可用
set_include\_path('/usr/lib/pear');

//在所有版本的PHP中均可用
ini_set('include\_path','/usr/local/pear');
?>

Examle 2
利用常量PATH_SEPATATOR可跨平台扩展include_path。
这个例子中我们把/usr/lib/pear添加到现有的include_path的尾部。

<?php
$path = '/usr/lib/pear';
set\_include\_path(get\_include\_path() . PATH_SEPARATOR . $path);

备注

对于一些老版本的php,PATH\_SEPARATOR是没有定义的,可以使用下面的命令来定义。

<?php
if( ! defined("PATH_SEPARATOR")) {
    if(strpos($_ENV["OS"], "Win") != false)
        define("PATH_SEPARATOR", ";");
    else define("PATH_SEPARATOR", ":");
}
?>

posted on 2016-03-12 23:23  队伍  阅读(730)  评论(0编辑  收藏  举报

导航