Tôi có mã PHP này:
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]);
}
}
Nếu tôi có một tệp có tên my.zip, hàm này trả về .zip.
Tôi muốn làm ngược lại, tôi muốn hàm trả về mymà không cần phần mở rộng.
Các tập tin chỉ là một chuỗi trong một biến.