function normalizeFilename(string $filePath): string {
// Extract only the file name
$filename = preg_replace('/^.*[\\\\\\/](.*)$/', '$1', $filePath);
// Replace whitespaces with underscores
$filename = str_replace(' ', '_', $filename);
// Convert to lowercase
$filename = strtolower($filename);
return $filename;
}
$filePath = "c:\\path\\to\\file\\WITH Whitespace1 and Whitespace2.php";
$result = normalizeFilename($filePath);
echo $result;
/*
run:
with_whitespace1_and_whitespace2.php
*/