In this article, you will learn how to get the following information in PHP.
- Directory name
- Basename
- Extension of file
- Filename
PHP pathinfo() returns the above information for a path in PHP.
what is the syntax of the PATHINFO function in php?
pathinfo(path, options)
Parameter | Description |
---|---|
path | Required. Specifies the path to be checked |
options | Optional. Specifies which array element to return. If not specified, it returns all elements.Possible values:PATHINFO_DIRNAME – return only dirnamePATHINFO_BASENAME – return only basenamePATHINFO_EXTENSION – return only extensionPATHINFO_FILENAME – return only filename |
examples of the PATHINFO function
Example 1. In this example, we get information about a file path.
<?php
print_r(pathinfo("/testweb/test.txt"));
?>