A php custom function to get the file extension

WBOY
Release: 2016-07-25 09:00:45
Original
1405 people have browsed it
  1. /*

  2. Get the file extension
  3. Usage: GetFiletype($filename)
  4. */

  5. function GetFiletype($Filename) {

  6. if (substr_count($Filename, ".") == 0) { // Check whether there is a . number in the file name.
  7. return; // Return empty
  8. } else if (substr($Filename, -1) == ".") { // Check if it ends with ., that is, no extension
  9. return; // Return empty
  10. } else {
  11. $FileType = strrchr ($Filename, "."); // Cut from . number
  12. $FileType = substr($FileType, 1); // Remove . number
  13. return $FileType; // Return
  14. }
  15. }

  16. $Filename = "index.php";

  17. $Filename = GetFileType($Filename);
  18. echo $Filename; // Print out php

Copy code


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!