Home  >  Article  >  Backend Development  >  Three ways to get file extension in php

Three ways to get file extension in php

WBOY
WBOYOriginal
2016-07-25 09:00:42853browse
  1. //取得文件的扩展名

  2. //by bbs.it-home.org
  3. //方法1
  4. function get_ext_file_1($file_name)
  5. {
  6. $retval = "";
  7. $pt = strrpos($file_name, ".");
  8. if ($pt) $retval=substr($file_name, $pt+1, strlen($file_name) - $pt);
  9. return ($retval);
  10. }

  11. //方法2

  12. function get_ext_file_2($file_name)
  13. {
  14. $get_ext_file = pathinfo($file_name);
  15. $get_ext_file = strtolower($get_ext_file["extension"]);
  16. return $get_ext_file;
  17. }

  18. //方法3

  19. function get_ext_file_3($file_name)
  20. {
  21. $get_ext_file =explode("." , $file_name);
  22. $va=count($get_ext_file)-1;
  23. return $get_ext_file[$va];
  24. }
  25. ?>

复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn