file-extension

How do I get (extract) a file extension in PHP?

寵の児 提交于 2019-11-25 21:58:02
问题 This is a question you can read everywhere on the web with various answers: $ext = end(explode(\'.\', $filename)); $ext = substr(strrchr($filename, \'.\'), 1); $ext = substr($filename, strrpos($filename, \'.\') + 1); $ext = preg_replace(\'/^.*\\.([^.]+)$/D\', \'$1\', $filename); $exts = split(\"[/\\\\.]\", $filename); $n = count($exts)-1; $ext = $exts[$n]; etc. However, there is always \"the best way\" and it should be on Stack Overflow. 回答1: People from other scripting languages always think