Tag Archive for filename

Regular expressions filename replace

// This will strip out any punctuation and spaces from filenames, replacing such characters with underscores
$filename = preg_replace("/[^a-zA-Z0-9s.]/", "_", $filename);

source

Get current filename

<?php
$currentFile = $_SERVER["PHP_SELF"];
$parts = Explode('/', $currentFile);
echo $parts[count($parts) - 1];
?>

or

<?php
basename($_SERVER[’PHP_SELF’]);
?>

source

Get a filename extension

//gets a filenames extension
function filename_extension($filename) {//{{{
$pos = strrpos($filename, '.');
if($pos===false) {
return false;
} else {
return substr($filename, $pos+1);
}
}//}}}

source

Function to Find File Name of Page Displayed

Function getFileName()
Dim lsPath, arPath
'Obtain the virtual file path
lsPath = Request.ServerVariables("SCRIPT_NAME")
'Split the path along the /s. This creates a one-dimensional array
arPath = Split(lsPath, "/")
'The last item in the array contains the file name
getFileName = arPath(UBound(arPath,1))
End Function

source