PHP » I/O » basename()

Syntax:
string basename(string filename [, string suffix])
filename
The name of the file.
suffix
Suffix to remove.

Strips a filename from path and suffix.

The basename() function returns a filename without the path. If the suffix parameter is provided, that suffix will also be removed.

Examples

Code:
<?php

$filename = "/var/tmp/phptest.log";
print "$filename<br>";
print basename($filename) . "<br>";
print basename($filename, ".log") . "<br>";
print basename($filename, "test.log");

?>
Output:
/var/tmp/phptest.log
phptest.log
phptest
php
Explanation:

This code shows how basename() can be used to modify a filename.

See Also: