How do I get a file extension in PHP?

前端 未结 28 2325
一向
一向 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 23:08

    Here is an example. Suppose $filename is "example.txt",

    $ext = substr($filename, strrpos($filename, '.', -1), strlen($filename));
    

    So $ext will be ".txt".

提交回复
热议问题