Menu Samaritan's Purse

PATHINFO

Returns information about a file path

SYNTAX

pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] ) : mixed

PARAMETERS

path

The path to be parsed.

options

If present, specifies a specific element to be returned; one of PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION or PATHINFO_FILENAME. If options is not specified, returns all available elements.

RETURN

If the options parameter is not passed, an associative array containing the following elements is returned: dirname, basename, extension (if any), and filename. If options is present, returns a string containing the requested element.

Note: If the path has more than one extension, PATHINFO_EXTENSION returns only the last one and PATHINFO_FILENAME only strips the last one.

Note: If the path does not have an extension, no extension element will be returned.

Note: If the basename of the path starts with a dot, the following characters are interpreted as extension, and the filename is empty.

EXAMPLES

1

/www/htdocs/inc
lib.inc.php
php
lib.inc

2

/www/htdocs/inc
lib.inc.php
php
lib.inc

3

string(0) ""
NULL

4

Array
(
    [dirname] => /some/path
    [basename] => .test
    [extension] => test
    [filename] =>
)

PHP