Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP pathinfo() Function

PHP pathinfo() Function

PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

The pathinfo() function returns information about a file path as an array.

The returned array elements are as follows:

Syntax

pathinfo(path,options)

Parameters Description
path Required. Specifies the path to check.
options Optional. Specifies the array element to return. Default is all.

Possible values:

  • PATHINFO_DIRNAME - Returns only dirname
  • PATHINFO_BASENAME - Returns only basename
  • PATHINFO_EXTENSION - Returns only extension
  • PATHINFO_FILENAME - Returns only filename
  • |

    Tips and Notes

    **Note:** If not all elements are requested, pathinfo() returns a string.


    Example

    Example 1

    The code above will output:

    Array
    (
        [dirname] => /testweb
        [basename] => test.txt
        [extension] => txt
        [filename] => test
    )
    

    Example 2

    The code above will output:

    test.txt
    

    PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual