How do I get a file extension in PHP?

前端 未结 28 2298
一向
一向 2020-11-21 22:45

This is a question you can read everywhere on the web with various answers:

$ext = end(explode(\'.\', $filename));
$ext = substr(strrchr($filename, \'.\'), 1         


        
28条回答
  •  爱一瞬间的悲伤
    2020-11-21 23:06

    If you are looking for speed (such as in a router), you probably don't want to tokenize everything. Many other answers will fail with /root/my.folder/my.css

    ltrim(strrchr($PATH, '.'),'.');
    

提交回复
热议问题