Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

pathinfo()

Example

Obtain details regarding a file path:

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

The following is the result of the code above:

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

Definition and Usage

A file path’s information is returned by the pathinfo() function.

Syntax

pathinfo(pathoptions)

Parameter Values

 

Parameter

Description

path

Essential. indicates the path that has to be examined.

options

Not required. indicates the array element to be returned. It returns all elements if nothing is given.
Potential amounts
• PATHINFO_DIRNAME – only returns the directory name

• PATHINFO_EXTENSION – return only extension;

• PATHINFO_BASENAME – return only basename
• PATHINFO_FILENAME: gives back just the filename

Technical Details

Return Value:

It returns an associative array containing dirname, basename, extension, and filename if the option parameter is not supplied. The requested element is returned in a string if the option parameter is supplied. When something fails, FALSE

PHP Version:

4.0.3+

PHP Changelog:

PATHINFO_FILENAME was added in PHP 5.2.

More Examples

Example

Obtain details regarding a file path:

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

The following is the result of the code above:

test.txt