Php method for getting the file suffix

Source: Internet
Author: User
Php method for getting the file suffix

  1. $ Pic = 'abc.3434.342.12123.123.exe ';

  2. $ Pics = explode ('.', $ pic );

  3. /* Obtain the total number of arrays and then take the last one */

  4. Echo $ num = count ($ pics );
  5. Echo'
    '. $ Pics [$ num-1];

  6. /* Traverse the array and obtain the last element */

  7. Foreach ($ pics as $ value) // 2
  8. {
  9. $ A = $ value;
  10. }
  11. Echo $ .'
    ';
  12. /* Directly output the last element of the array */
  13. Echo end ($ pics );
  14. Echo'
    ';
  15. /* Pay attention to the difference between the last element of a single-output array and end */
  16. // Echo array_pop ($ pics );
  17. /* Sort the array in reverse order based on the key value, and then output the first element */
  18. Krsort ($ pics );
  19. Echo array_shift ($ pics );
  20. Echo'
    ';

  21. /* The value corresponding to the extension index returned by the pathinfo () function */

  22. $ Res = pathinfo ($ pic); // 5
  23. Var_dump ($ res );
  24. Echo $ res ['extension'].'
    ';

  25. /* Extract the string and take the last three digits */

  26. Echo substr ($ pic,-3, 3 );
  27. ?>

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.