Tuesday, November 15, 2011

PHP : Getting filename from a URL

Some time using PHP, you might need to get the path from a URL, leaving behind just the filename at the end of the URL. You can achieve this with a regular expression pattern of course, but here is a much simple way to strip the file name from url using PHP.

Example:


      $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];


      $filename = basename($url);

     echo $filename;
?>
Hope you will enjoy this... :)

No comments:

Post a Comment

Please Comment Here!

How to backup and download Database using PHP

< ?php $mysqlUserName = 'databaseusername' ; $mysqlPassword = 'databasepassword' ; $mysqlHostNa...