21st January 2021
PHP [Versions: 4 >= 4.0.3, 5, 7, 8]
Returns information about a file path.
- 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:
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.
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”.
Used In Projects
Was This Helpful?
If this post has helped you, please let me know. Your feedback will be highly appreciated and will help me build better content.