You Try code
$filename = "refinish.php";
$extension_pos = strrpos($filename , '.');
$file = substr($filename, 0, $extension_pos) ;
$folder = str_replace('.','',rtrim( $file , "php"));
echo $folder.substr($filename, $extension_pos);
its working fine . its output is refinis.php