PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8
pathinfo - Returns information about a file path
Code Examples

pathinfo( string$path, [int$flags = PATHINFO_ALL] ): array|string

pathinfo returns information about path: either an associative array or a string, depending on flags.


For information on retrieving the current path info, read the section on predefined reserved variables.


pathinfo operates naively on the input string, and is not aware of the actual filesystem, or path components such as "..".


pathinfo is locale aware, so for it to parse a path containing multibyte characters correctly, the matching locale must be set using the setlocale function.



The path to be parsed.


If present, specifies a specific element to be returned; one of PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION or PATHINFO_FILENAME.

If flags is not specified, returns all available elements.

Return Values

If the flags parameter is not passed, an associative array containing the following elements is returned: dirname, basename, extension (if any), and filename.


If the path has more than one extension, PATHINFO_EXTENSION returns only the last one and PATHINFO_FILENAME only strips the last one. (see first example below).


If the path does not have an extension, no extension element will be returned (see second example below).


If the basename of the path starts with a dot, the following characters are interpreted as extension, and the filename is empty (see third example below).

If flags is present, returns a string containing the requested element.

Related Functions

Example of pathinfo

Show all examples for pathinfo

PHP Version: