pathinfo
pathinfo
Returns information about a file path
**pathinfo** string $path int $flags
returns information about
: either an associative array or a string,
depending on .
pathinfo``path``flags
Opmerking: > For information on retrieving the current path info, read the section on . predefined reserved variables
Opmerking: > operates naively on the input string, and is not aware of the actual filesystem, or path components such as "".
pathinfo``..
Opmerking: > On Windows systems only, the character will be interpreted as a directory separator. On other systems it will be treated like any other character.
\
Let op: > is locale aware, so for it to parse a path containing multibyte characters correctly, the matching locale must be set using the function.
pathinfo``setlocale
pathThe path to be parsed.
flags
If present, specifies a specific element to be returned; one of
,
,
or
.
PATHINFO_DIRNAME``PATHINFO_BASENAME``PATHINFO_EXTENSION``PATHINFO_FILENAME
If is not specified, returns all
available elements.
flags
If the parameter is not passed, an
associative containing the following elements is
returned:
, ,
(if any), and .
flags``array``dirname``basename``extension``filename
Opmerking: > If the has more than one extension, returns only the last one and only strips the last one. (see first example below).
path``PATHINFO_EXTENSION``PATHINFO_FILENAME
Opmerking: > If the does not have an extension, no element will be returned (see second example below).
path``extension
Opmerking: > If the of the starts with a dot, the following characters are interpreted as , and the is empty (see third example below).
basename``path``extension``filename
If is present, returns a
containing the requested element.
flags``string
Voorbeeld: Example
<?php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n";
?>
/www/htdocs/inc
lib.inc.php
php
lib.inc
Voorbeeld: example showing difference between null and no extension
<?php
$path_parts = pathinfo('/path/emptyextension.');
var_dump($path_parts['extension']);
$path_parts = pathinfo('/path/noextension');
var_dump($path_parts['extension']);
?>
string(0) ""
Notice: Undefined index: extension in test.php on line 6
NULL
Voorbeeld: example for a dot-file
<?php
print_r(pathinfo('/some/path/.test'));
?>
Array
(
[dirname] => /some/path
[basename] => .test
[extension] => test
[filename] =>
)
Voorbeeld: example with array dereferencing
The parameter is not a bitmask. Only a single value
may be provided. To select only a limited set of parsed values, use array
destructuring like so:
`flags`
<?php
['basename' => $basename, 'dirname' => $dirname] = pathinfo('/www/htdocs/inc/lib.inc.php');
var_dump($basename, $dirname);
?>
string(11) "lib.inc.php"
string(15) "/www/htdocs/inc"
dirname``basename``parse_url``realpath