I have this PHP code:
function ShowFileExtension($filepath)
{
preg_match('/[^?]*/', $filepath, $matches);
$string = $matches[0];
$pattern = preg_split('/./', $string, -1, PREG_SPLIT_OFFSET_CAPTURE);
if(count($pattern) > 1)
{
$filenamepart = $pattern[count($pattern)-1][0];
preg_match('/[^?]*/', $filenamepart, $matches);
return strtolower($matches[0]);
}
}
If I have a file named my.zip
, this function returns .zip
.
I want to do the reverse, I want the function to return my
without the extension.
The file is just a string in a variable.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…