Home > Backend Development > PHP Tutorial > 5 ways to get file extension in php

5 ways to get file extension in php

WBOY
Release: 2016-07-25 09:00:40
Original
1209 people have browsed it
  1. //Get file extension

  2. $file = 'jbxue.com.php';

  3. //Method 1

  4. $path_info = pathinfo($file);
  5. //print_r($path_info);
  6. //echo "
    ";
  7. //echo $path_info['dirname'];
  8. //echo "
    ";
  9. //echo $path_info['basename'];
  10. echo "
    ";
  11. echo strtolower($path_info['extension']);

  12. //Method 2

  13. echo "---------------------
    ";
  14. $p = strrpos($file,'.'); //Get the last point The position of
  15. echo strtolower(substr($file,$p+1));

  16. //Method 3

  17. echo "--------------- ------
    ";
  18. $arr = explode('.',$file);
  19. echo strtolower($arr[count($arr)-1]);

  20. //Method 4

  21. echo "---------------------
    ";
  22. $arr = explode('.' ,$file);
  23. echo strtolower(end($arr));

  24. //Method 5

  25. echo "----------------- ----
    ";
  26. preg_match('/.(w+)$/',$file,$extend);
  27. echo strtolower($extend['1']);

  28. //Method 6

  29. echo "---------------------
    ";
  30. //strrchr($file,' .') from the last occurrence position to the last string
  31. echo strtolower(substr(strrchr($file,'.'),1));
  32. //by http://bbs.it-home.org
  33. ?>

Copy the code

Attachment: A little knowledge about extensions A file extension is a mechanism used by the operating system to identify a file format. Normally, an extension follows the main file name, separated by a delimiter. In a file name like "readme.txt", readme is the main file name and txt is the extension, indicating that the file is considered a plain text file.



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