basename()

basename()

Following example show how to get the filename of current page

$PHP_SELF = $_SERVER[’PHP_SELF’];
echo basename($PHP_SELF);

basename(string path,string suffix) –> returns the filename.
- First argument is used to get the path
- Second argument is optional, basically used to remove the suffix like .php and ect.

For example

$path = “/work/test/test.php”;
$fileName1 = basename ($path);
$fileName2 = basename ($path,”.php”);

NOw $fileName1 contains test.php and $fileName2 contains test only

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.