PHP's very useful advanced functions PATH_SEPARATOR constant and set_include_path
Release: 2016-08-08 09:29:13
Original
1118 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.0set_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.
Syntaxpathinfo(path,options)
Copy after login
ParametersDescription
path |
Required. Specifies the path to be checked. |
process_sections |
| Optional. Specifies the array elements to be returned. The default is all.
Possible values: |
PATHINFO_DIRNAME - only returns dirname PATHINFO_BASENAME - only returns basename PATHINFO_EXTENSION - only returns extension
| pathinfo() Returns an associative array containing
path Information.
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:
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.
|
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31