Easy Tutorial
❮ Php Restful Php Is_Object Function ❯

PHP pathinfo() Function

Complete PHP Filesystem Reference Manual


Definition and Usage

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

The returned array elements are as follows:

Syntax

Parameter Description
path Required. Specifies the path to check.
options Optional. Specifies which array elements to return. Default is all. Possible values: PATHINFO_DIRNAME - Returns only dirname<br> PATHINFO_BASENAME - Returns only basename<br> PATHINFO_EXTENSION - Returns only extension<br> PATHINFO_FILENAME - Returns only filename

Tips and Notes

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


Examples

Example 1

<?php
print_r(pathinfo("/testweb/test.txt"));
?>

The above code will output:

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

Example 2

<?php
print_r(pathinfo("/testweb/test.txt", PATHINFO_BASENAME));
?>

The above code will output:

test.txt

Complete PHP Filesystem Reference Manual

❮ Php Restful Php Is_Object Function ❯