Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function basename()


previous

Advertisements

Syntax

string basename ( string $path [, string $suffix] );

Definition and Usage

Given a string containing a path to a file, this function will return the base name of the file.

Paramters

ParameterDescription
pathA file path.
suffixIf the filename ends in suffix this will also be cut off.

Return Value

Returns the base name of the given path.

Example

Following is the usage of this function:

<?php
$path = "/home/httpd/html/index.php";
$file = basename($path);         
echo "File name is $file\n";
$file = basename($path, ".php");
echo "File name is $file\n";
?>

This will produce following result:

File name is index.php
File name is index

previous Printer Friendly

Advertisements


  

Advertisements