php中的路径问题与set_include_path使用介绍

yipeiwu_com5年前PHP代码库
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
?>

相关文章

php 中文字符入库或显示乱码问题的解决方法

大家以后在编写过程中, 一定要记得定义字符类型。mysql_query("set names 'gbk'") 解决的方法就这么简单。 今天做了一个数据库查询,放出代码。 复制代码 代码如...

php ss7.5的数据调用 (笔记)

php ss7.5的数据调用 (笔记)

这几天搞 ss7.5 dz7.2 uc1.5 uchome2.0和自己主站的整合 头都大了 呵呵  好歹是弄的差不多 了 呵呵 记录一下 ss7.5的数据调用  ...

php创建多级目录代码

function createFolder($path) {    if (!file_exists($path))  &nb...

PHP一致性hash分布式算法封装类定义与用法示例

本文实例讲述了PHP一致性hash分布式算法封装类定义与用法。分享给大家供大家参考,具体如下: 一、无虚拟节点实现 <?php /** * 一致性hash分布式算法...

深入解析PHP垃圾回收机制对内存泄露的处理

上次说到了refcount和is_ref,这里来说说内存泄露的情况复制代码 代码如下:$a = array(1, 2, &$a);unset($a);在老的PHP版本中,这里就会出现内存...