Php file extension

Source: Internet
Author: User
Php file extension

  1. // Get the file suffix

  2. // By bbs.it-home.org

  3. $ File_name = "jbxue.com.txt ";

  4. Echo get_exname ($ file_name );
  5. /**
  6. * Get the file extension
  7. * @ Param unknown_type $ file_name
  8. * @ Return $ ex_name
  9. */
  10. Function get_exname ($ file_name)
  11. {
  12. If (empty ($ file_name ))
  13. Return false;
  14. $ File_name = strtolower ($ file_name );
  15. $ Rev_str = strrev ($ file_name );
  16. $ Ex_name_len = strpos ($ rev_str, '.'); // The length of the extension.
  17. $ File_name_len = strlen ($ file_name );
  18. $ Ex_name = substr ($ file_name, $ file_name_len-$ ex_name_len );
  19. Return $ ex_name;
  20. }
  21. ?>

Function explanation: the strtolower () function converts a string to lowercase. The strrev () function reverses the string. The strpos () function returns the position where the string first appears in another string. Find the position of the symbol '.' and calculate the length of the extension. Use the total length of the string minus the extension length to calculate the length to be truncated.

Looking back, we have introduced multiple methods to get file extensions: three methods for php to get file extensions (available version) php file extension retrieval methods summary php three methods for getting File extensions php 5 methods for getting File extensions one method for getting File extensions php user-defined functions php for getting file extensions to the front of happiness, may you find the sunshine on your way to learning at the programmer's home, so that you can spend a great time in your young and colorful life.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.