Home > Backend Development > PHP Tutorial > Three ways to get file extension in php (improved version)

Three ways to get file extension in php (improved version)

WBOY
Release: 2016-07-25 09:00:44
Original
892 people have browsed it
  1. //取文件的扩展名

  2. //by http://bbs.it-home.org

  3. //method 1

  4. function get_file_ext_1($fileName){
  5. $retval="";
  6. $pt=strtpos($fileName,".");
  7. if($pt){
  8. $retval=substr($fileName,$pt+1,strlen($fileName)-$pt);
  9. }
  10. if($retval!==""){
  11. return $retval;
  12. }
  13. return false;
  14. }

  15. //method two

  16. function get_file_ext_2($fileName){
  17. $extend = pathinfo($fileName);
  18. $extend = strtolower($extend['extension']);
  19. if(is_string($extend)){
  20. return $extend;
  21. }
  22. return false;
  23. }

  24. //method three

  25. function get_file_ext_3($fileName){
  26. $extend =explode(".",$fileName);
  27. $va=count($extend)-1;
  28. $extend =$extend[$va];
  29. if(is_string($extend)){
  30. return $extend;
  31. }
  32. return false;
  33. }
  34. ?>

复制代码


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template