PHP's very useful advanced functions PATH_SEPARATOR constant and set_include_path

WBOY
Release: 2016-08-08 09:29:13
Original
1067 people have browsed it
zendframework’s example index.php has this sentence set_include_path('.' . PATH_SEPARATOR . '../library/'. PATH_SEPARATOR . './application/models/'. PATH_SEPARATOR . './application/lib/'. In fact, it is a constantYou can know its value by directly echoing it. On Linux, it is a ":" sign, and on WIN, it is a ";" sign. Set_include_path is to set the include file path of php, which is quite the environment of the operating system. Variables// Works as of PHP 4.3.0

set_include_path('/inc'); // Works in all PHP versionsini_set('include_path', '/inc');?> Regarding the issue of set_include_path, under win, when you want to include multiple paths, you have to separate them with ";", but under Linux, use ";": "Separated. So the zf code above is a perfect match. get_include_path gets the currently existing environment variable Definition and usage pathinfo() function returns the file path information in the form of an array.
Syntax
pathinfo(path,options)
Copy after login

Parameters

DescriptionOptional. Specifies the array elements to be returned. The default is all. Possible values: pathinfo() Returns an associative array containing path Information.
path Required. Specifies the path to be checked.
process_sections
PATHINFO_DIRNAME - only returns dirname

PATHINFO_BASENAME - only returns basename

PATHINFO_EXTENSION - only returns extension
  • Description

Includes the following array elements:

[dirname]

[basename]

[extension]
  • Tips and Notes
  • Note: If it is not required to obtain all units, the pathinfo() function returns characters string.

Example

Example 1

<?php
print_r(pathinfo("/testweb/test.txt"));
?>
Copy after login
Output:
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)
Copy after login

Example 2

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

Output:

test.txt
Copy after login

DIRECTORY_SEPARATOR window below

Instructions Path separator

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");} Reprinted from: http:// www.cnblogs.com/jackluo/archive/2013/04/09/3010257.html

The above has introduced PHP's very useful advanced functions PATH_SEPARATOR constant and set_include_path, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!