English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP pathinfo() Function Usage and Example

PHP Filesystem Reference Manual

The pathinfo() function can return an array containing information about the path. If options are specified, it will return the specified elements; they include: PATHINFO_DIRNAME, PATHINFO_BASENAME, and PATHINFO_EXTENSION or PATHINFO_FILENAME. If no options are specified, it defaults to returning all elements.

Syntax

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

The pathinfo() function can return information about the path: an associative array or a string, depending on the options.

Example1

<?php
   print_r(pathinfo("/PhpProject/simple.txt"));
?>

Output Result

Array
(
    [dirname] => /PhpProject1
    [basename] => simple.txt
    [extension] => txt
    [filename] => simple
)

Example2

<?php
   print_r(pathinfo("/PhpProject/simple.txt, PATHINFO_BASENAME));
?>

Output Result

simple.txt

PHP Filesystem Reference Manual