15 1 0 4000 1 https://codeblock.co.za 300 true 0
theme-sticky-logo-alt

pathinfo()

0 Comments

Programming Language

PHP [Versions: 4 >= 4.0.3, 5, 7, 8]

Syntax

Typical Usage

Returns information about a file path.

Accepted Parameters

  • path (string) (Required): The path to be parsed.
  • flags (integer) (Optional) (DefaultĀ  = PATHINFO_ALL): Specifies a specific element to be returned. Flags may include any one of the following parameters:
    • PATHINFO_DIRNAME
    • PATHINFO_BASENAME
    • PATHINFO_EXTENSION
    • PATHINFO_FILENAME.

Return Value(s)

If the flags parameter is not passed, an associative array containing the following elements is returned: dirname, basename, extension (if any), and filename. Otherwise, returns a string of the request flag.

Notes

If the basename of the path starts with a period the filename will be empty.

Examples of pathinfo()

Example 1: Get a File’s Extension in PHP

<?php
$file = '/images/myfile.png';
$ext = pathinfo($file, PATHINFO_EXTENSION);
print_r($ext);

The above will print “png”.

Was This Helpful?

Previous Post
str_split()
Next Post
fopen()

0 Comments

Leave a Reply