php中的路径问题与set_include_path

first:

php中常用的路径

当前文件路径:D:\phpweb\php_example\include_path.php

1.dirname(__FILE__); //输出D:\phpweb\php_example

2.$_SERVER['SCRIPT_FILENAME']; //输出D:/phpweb/php_example/include_path.php

second:

php中的set_include_path

在php中,include文件时,当包含路径不为相对也不为绝对时(如:include("example.php")),会先查找include_path所设置的目录,然后再在当前目录查找,这也是为什么很多资料上提到include("./example.php")比include("example.php")效率高的原因。

方法:

1.ini_set("include_path", "/usr/lib/pear"); //所有版本
        2.set_include_path("/usr/lib/pear"); //version>=4.3.0

可以用下面的方法,在原有目录上添加目录

<?php

$path = '/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);//设置后的include_path变为类似/usr/lib/function;/usr/lib/pear
    ?>

欢迎交流,我是luluyrt@163.com


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值