PHP pathinfo() Function
In this chapter you will learn:
- Definition for PHP pathinfo() Function
- Syntax for PHP pathinfo() Function
- Parameter for PHP pathinfo() Function
- Return for PHP pathinfo() Function
- Example - returns an array that contains information about a path
Definition
The pathinfo() function returns an array that contains information about a path.
Syntax
PHP pathinfo() Function has the following syntax.
pathinfo(path,options)
Parameter
Parameter | Is Required | Description |
---|---|---|
path | Required. | Path to check |
options | Optional. | Which array elements to return. Default is all |
Possible values for options:
- PATHINFO_DIRNAME - return only dirname
- PATHINFO_BASENAME - return only basename
- PATHINFO_EXTENSION - return only extension
Return
If the options parameter is not passed, an associative array containing the following elements is returned: dirname, basename, extension (if any), and filename.
Example
The pathinfo() function takes a filename as its only parameter and returns an array with three elements: dirname, basename, and extension.
Dirname contains the name of the directory the file is in, basename contains the base filename, and extension contains the file extension, if any (e.g., html or txt).
You can see this information yourself by running this script:
<?PHP/*from ja v a 2 s .co m*/
$filename = "test.txt";
$fileinfo = pathinfo($filename);
var_dump($fileinfo);
print_r(pathinfo("test.txt",PATHINFO_BASENAME));
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP pclose() Function
- Syntax for PHP pclose() Function
- Parameter for PHP pclose() Function
- Return for PHP pclose() Function
- Example - Close a pipe opened by popen()