PHP Basename

DescriptionPHP snippet by - 12/04/10

This is a quick PHP technique to extract the filename from a url or path. Just pass a string or url through the basename function and only the filename will be returned. The second argument for this function is for the suffix, so if you set the second argument to ".php", then the file name will be returned without the file extension.

More InformationGoto Reference Page

Tags ,

<?php
$file_url = "http://hyperspatial.com/myfile.php";
echo basename($file_url);
?>
  • Share
Authored by: Adam J Nowak
http://hyperspatial.com

Comments and Feedback