• PHP Video Tutorials

PHP - Function pathinfo()



The pathinfo() function can return an array that contains information about a path. If the options parameter is not passed, an associative array containing the elements is returned: dirname, basename, extension (if any), and filename.

Syntax

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

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

Example-1

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

Output

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

Example-2

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

Output

simple.txt
php_function_reference.htm
Advertisements