PHP - 获取和设置include_path .

PHP - 获取和设置include_path

分类:             PHP              2011-02-16 13:19     2818人阅读     评论(1)     收藏     举报

includepathphpinijava

include_path是PHP中的一个环境变量,在php.ini中初始化设置,类似于JAVA的CLASSPATH和操作系统中的PATH。

例如:有如下一些文件, /www/index.php /www/includes/config.php /www/includes/functions.php /www/includes/PEAR/PEAR.php /www/includes/PEAR/DB.php /www/includes/PEAR/DB/mysql.php

如果没有设置include_path变量,index.php需要这样写:

[php] view plaincopyprint?

  1. <?php
  2. include_once ‘/www/includes/config.php‘;
  3. include_once ‘/www/includes/PEAR/DB.php‘;
  4. include_once ‘/www/includes/PEAR/DB/mysql.php‘;
  5. ?>

<?php

include_once ‘/www/includes/config.php‘;
include_once ‘/www/includes/PEAR/DB.php‘;
include_once ‘/www/includes/PEAR/DB/mysql.php‘;

?>

使用上面的引用方式,引用路径比较长,当引用目录位置改变时需要大量修改代码。使用include_path变量可以简化上述问题:

[php] view plaincopyprint?

  1. <?php
  2. set_include_path(/www/includes‘ . PATH_SEPARATOR . /www/includes/PEAR‘);
  3. include_once ‘config.php‘;
  4. include_once ‘DB.php‘;
  5. include_once ‘DB/mysql.php‘;
  6. ?>

<?php

set_include_path(/www/includes‘ . PATH_SEPARATOR . /www/includes/PEAR‘);

include_once ‘config.php‘;
include_once ‘DB.php‘;
include_once ‘DB/mysql.php‘;

?>

include_path是PHP的环境变量,因而可以在php.ini设置,每次请求时include_path都会被PHP用php.ini中的值初始化。也可以用代码的方式修改include_path值,不过,修改后结果在请求完毕后会自动丢弃,不会带到下一个请求。因此,每次请求时需要重新设置。

在代码中获取和设置include_path值有如下两种方式:

方式一:ini_get()和ini_set()方式,此种方式使用于所有PHP版本。

[php] view plaincopyprint?

  1. <?php
  2. $s = ini_get(‘include_path‘);
  3. ini_set($s . PATH_SEPARATOR . ‘/www/includes‘);
  4. ?>

<?php

$s = ini_get(‘include_path‘);

ini_set($s . PATH_SEPARATOR . ‘/www/includes‘);

?>

方式二:get_include_path()和set_include_path()方式,此种方式使用于PHP4.3以后的版本。

[php] view plaincopyprint?

  1. <?php
  2. $s = get_include_path();
  3. set_include_path($s . PATH_SEPARATOR . ‘/www/includes‘);
  4. ?>

<?php

$s = get_include_path();

set_include_path($s . PATH_SEPARATOR . ‘/www/includes‘);

?>

时间: 2024-08-26 10:14:05

PHP - 获取和设置include_path .的相关文章

JavaScript设置获取和设置属性的方法

这篇文章主要介绍了JavaScript设置获取和设置属性的方法,学会使用getAttribute.setAttribute的用法,需要的朋友可以参考下 getAttribute 该方法用来获取元素的属性,调用方式如下所示: 复制代码代码如下: object.getAttribute(attribute) 以此前介绍的一些方法不同,getAttribute方法不属于document对象,所以不能通过document对象调用.它只能通过元素节点对象来调用. 该方法只接受一个参数,你指定要查询的属性的

jQuery获取和设置disabled属性、背景图片路径

之前对于这个独特的disabled属性获取和设置很混乱,今天项目中用到了,用attr不能实现,于是多次试验得出: 获取disabled属性用prop $("#basic_key").prop("disabled") 以上会返回true或false. 然后设置disabled是attr,重点是后面的一个参数不加引号: $("#basic_key").attr("disabled",'false') //false加引号是错误的~

Delphi获取与设置系统时间格式,即GetLocaleInfo和SetLocaleInfo

在Delphi中,特别是在写管理系统软件时,经常要用到 FormatDateTime 以将 TDateTime 格式的日期时间转换成字符串形式的值显示或保存起来,或者用 StrToDateTime将字符串形式的日期时间转换成 TDateTime 然后再做其他操作. 在进行时间或日期的转换时,会使用系统当前设定的时间日期格式.而如果时间日期格式与字符串中的表示方式不相符,会使转换过程失败.例如当前短日期格式设定为'yyyy/MM/dd',而要转为 '2006-10-20'这样的字符串为日期,就会报

Java并发学习之二——获取和设置线程信息

本文是学习网络上的文章时的总结,感谢大家无私的分享. Thread类的对象中保存了一些属性信息能够帮助我们辨别每一个线程,知道它的一些信息 ID:每个线程的独特标示: Name:线程的名称: Priority:线程对象的优先级.优先级别在1-10之间,1是最低级,10是最高级. Status:线程状态.在java中,线程只有6种状态:new,runnable,blocked,waiting,time waiting 或terminated. 现在写一个程序,将线程的信息保存到文件中方便查看 pa

How do I get an image from an UIButton? 如何获取uibutton设置的uiimage

UIImage*img =[button imageForState:UIControlStateNormal];How do I get an image from an UIButton? 如何获取uibutton设置的uiimage,码迷,mamicode.com How do I get an image from an UIButton? 如何获取uibutton设置的uiimage

常见位操作:获取,设置,清零

1 /*常见位操作:获取,设置,清零 2 * 3 * */ 4 public class BitGet { 5 /* 6 * 该函数实现获取功能 7 * 先将1左移动i位,左移动0位变成了00000001, 8 * 然后再和Num十进制12转化为二进制00001100进行&运算, 9 * 00000001 如果是左移动两位就为 00000100 10 * 00001100 00001100 11 * -------- -------- 12 * 00000000 00000100 13 * 从而

jQuery -&gt; 获取/设置/删除DOM元素的属性

Sum square difference Problem 6 The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of

jQuery -&gt; 获取/设置HTML或TEXT内容

jQuery提供了两个API可以直接用来为元素添加内容. html() text() 其中html()是为指定的元素添加html内容 text()是为指定的元素添加文本内容 两者的区别在于,text中的内容是纯文本,不会被解析为html 如果要对如下html代码进行操作 <body> <p></p> </body> 使用html() $('p').html('<strong>Hello World</strong>, I am a &

js获取并设置&lt;p&gt;&lt;/p&gt;的显示的值。

原文链接:http://www.nowamagic.net/librarys/posts/jquery/23 html()方法 此方法类似于JavaScript中的innerHTML属性,可以用来读取或者设置某个元素中的HTML内容.要获取某个元素的内容,可以这样: 1 var p_html = $("p").html(); //获取p元素的HTML代码  如果需要设置某元素的HTML代码,那么也可以使用该方法,不过需要为它传递一个参数.例如要设置p元素的HTML代码,可以使用如下代码