Get file name and remove file extension using php

Get a File name from url Using PHP
Get the “filename”, or the last part of the string, with the basename function.


$url = ‘’;
echo basename($url); // print “index.php”;
Remove a File Extention Using PHP
To strip the file extension from a file name you can use the combination of strrpos() and substr() function like this :
$fileName =”index.php”;
$name = substr($fileName, 0, strrpos($fileName, ‘.’));
echo $name; //print “index”

Like to share it

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *