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... :)

How to change the PHP version for subfolders or subdomains

  How to change the PHP version for subfolders or subdomains Setting a specific PHP version for a specific websites, subfolders or subdomain...