Heim  >  Artikel  >  Backend-Entwicklung  >  php 非常有用的高级函数PATH_SEPARATOR常量和set_include_path

php 非常有用的高级函数PATH_SEPARATOR常量和set_include_path

WBOY
WBOYOriginal
2016-08-08 09:29:131075Durchsuche
zendframework的示例index.php里有这样一句 set_include_path('.' . PATH_SEPARATOR . '../library/'. PATH_SEPARATOR . './application/models/'. PATH_SEPARATOR . './application/lib/'. PATH_SEPARATOR . get_include_path()); 不知道 PATH_SEPARATOR是什么,其实就是一个常量直接echo就知道它的值了,在linux上是一个":"号,WIN上是一个";"号set_include_path就是设置php的包含文件路径,相当是操作系统的环境变量 // Works as of PHP 4.3.0set_include_path('/inc'); // Works in all PHP versionsini_set('include_path', '/inc');?> 关于set_include_path的问题,在win下,当你要include多个路径的话,你要用";"隔开,但在linux下就使用":"隔开的。所以上面的zf的代码真是绝配.
get_include_path取得当前已有的环境变量

定义和用法

pathinfo() 函数以数组的形式返回文件路径的信息。

语法

pathinfo(path,options)
参数 描述
path 必需。规定要检查的路径。
process_sections

可选。规定要返回的数组元素。默认是 all。

可能的值:

  • PATHINFO_DIRNAME - 只返回 dirname
  • PATHINFO_BASENAME - 只返回 basename
  • PATHINFO_EXTENSION - 只返回 extension

说明

pathinfo() 返回一个关联数组包含有 path 的信息。

包括以下的数组元素:

  • [dirname]
  • [basename]
  • [extension]

提示和注释

注释:如果不是要求取得所有单元,则 pathinfo() 函数返回字符串。

例子

例子 1

<?php print_r(pathinfo("/testweb/test.txt"));
?>

输出:

Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)

例子 2

<?php print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
?>

输出:

test.txt
 DIRECTORY_SEPARATOR   window 下面说明  

路径分隔符

windows

\ or /

linux

/

function __autoload($classname){  if(preg_match('/\\\\/',$classname)){    $path = str_repace('\\',DIRECTORY_SEPARATOR,$classname);      }else{       $path = str_replace('_',DIRECTORY_SEPARATOR,$classname);     }   require_once("$path.php");}转载自:http://www.cnblogs.com/jackluo/archive/2013/04/09/3010257.html

以上就介绍了php 非常有用的高级函数PATH_SEPARATOR常量和set_include_path,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn