basename() Get Filename PHP Filesystem Function

basename php filesystem function example - returns file name from given path

basename-php-filesystem-function-example.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>basename php filesystem function example - returns file name from given path</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="basename php filesystem function example - returns file name from given path">
  <meta name="keywords" content="php, example, code, file, function, filesystem, filestream">
  <meta name="description" content="basename php filesystem function example - returns file name from given path">
  <style>
   h2, h4{background:#eee; color:#000085;}
   h2{ padding:3px; margin:3px; font-size:22px;}
   h4{ padding:2px; margin:2px; font-size:19px;}
   p{padding:2px; margin:2px; color:#0099FE;}
   body{ background:#FFFFFC;}
  </style>
 </head>
 <body>
  <h2>basename php filesystem function example - returns file name from given path</h2>
  <pre>
   <?php
    /*
     -------------------------------------------------------------------
     let say we have a file name called test.php in local server,
     we would like to find out the basename or filename from the path
     by using php basename function.
     -------------------------------------------------------------------
    */
    $filePath = "http://127.0.0.1/phpexamplecode/test.php";
    echo "<h4>Output of filePath in the browser</h4>";
    print "<p>$"."filePath = {$filePath}</p>";
    /*
     -----------------------------------------------------------
     find the basename using php filesystem basename function
     -----------------------------------------------------------
    */
    $basename = basename($filePath);
    echo "<h4>Output of basename in the browser</h4>";
    print "<p>$"."basename = {$basename}</p>";
    /*
     -----------------------------------------------------------------------------
     we can omit file extension by passing another argument to basename funciton
     -----------------------------------------------------------------------------
    */
    $extension = ".php";
    $basename = basename($filePath, $extension);
    echo "<h4>Output of basename without extension \'{$extension}\' in the browser</h4>";
    print "<p>$"."basename = {$basename}</p>";
   ?>
  </pre>
 </body>
</html>

basename php filesystem function example - returns file name from given path - output in the browser

 

Related Tutorial Examples

  1. Use of Switch in PHP Tutorial Example
  2. Use of ELSE IF in PHP Tutorial Example
  3. Use of IF in PHP Tutorial Example
  4. Apache mod_rewrite Example - Forbidding Direct Script Access
  5. Apache mod_rewrite Example - SEO Friendly URLs
  6. Apache mod_rewrite Example - Hellow World!! Program Using Htaccess
  7. Apache mod_rewrite Example - MOD_Rewrite Status Test
  8. 19 Examples to Learn MySQL
  9. 20 steps to make CakePHP Blog Project
  10. file() Read File PHP Filesystem Function Example

No comments:

Post a Comment

leave your comments here..