Get Page Name or File Name or Extension from Page URL

If you want to know Page Name, File Name, File Extension and directory name from a URL then you can use following function for it in PHP.
[php]$path_name = "abc/xyz/name.somename.txt";
$path_parts = pathinfo($path_name);

echo $path_parts[‘dirname’], "n";
echo $path_parts[‘basename’], "n";
echo $path_parts[‘extension’], "n";
echo $path_parts[‘filename’], "n";[/php]

For more information you can visit: http://php.net/manual/en/function.pathinfo.php
You can access its array and if you want to directly access value then you can do it by following:
[php]$path_filename=pathinfo($pathname, PATHINFO_FILENAME);[/php]

Similarly, for File Name
[php]$path_extension=pathinfo($pathname, PATHINFO_EXTENSION);[/php]

Leave a Comment