pathinfo() function basically contains the information of the file path. It will take two parameters:
- path(required) : path whose information is needed.
- options(optional) :tells which elements to return. Values are PATHINFO_DIRNAME(returns directory name), PATHINFO_BASENAME(return basename), PATHINFO_EXTENSION(return extension), PATHINFO_FILENAME (return filename)
This function returns an array or string depends upon the value of options. By deafult, all values are returned if options is not set.
For example:
<?php
$path_info = pathinfo('/www/htdocs/demo.php');
echo $path_info['dirname'], "\n";
echo $path_info['basename'], "\n";
echo $path_info['extension'], "\n";
echo $path_info['filename'], "\n"; // since PHP 5.2.0
?>
When you will execute the above script it will display:
/www/htdocs
demo.php
php
demo
0 Comment(s)