From 5920992c90b3a4770795068b7e5c31c059070670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=9A=84=E5=A6=82=E6=9E=9C?= Date: Mon, 8 Jan 2024 16:38:25 +0800 Subject: [PATCH] add file ext parser --- src/File.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/File.php b/src/File.php index 05c3dc8..ecc1394 100644 --- a/src/File.php +++ b/src/File.php @@ -243,4 +243,18 @@ static function scanDirectory($dirPath) return [ 'files' => $fileContainer, 'dirs' => $dirContainer ]; } + + + static function getExt(string $file,bool $withDot = false):?string + { + $list = explode(".",$file); + if(count($list) < 2){ + return null; + } + $ext = array_pop($list); + if($withDot){ + return '.'.$ext; + } + return $ext; + } } \ No newline at end of file