Home  >  Article  >  Backend Development  >  How to get file extension in php

How to get file extension in php

WBOY
WBOYOriginal
2016-07-25 09:03:28934browse
  1. $pic = 'abc.3434.342.12123.123.exe';

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

  3. < p>/*Get the total number of the array, and then take the last one*/
  4. echo $num = count($pics);
  5. echo '
    '.$pics[$num-1];

  6. < ;p>/*Traverse the array and get the last element*/
  7. foreach ($pics as $value) //2
  8. {
  9. $a = $value;
  10. }
  11. echo $a.'
    ';
  12. /*Directly output the last element of the array*/
  13. echo end($pics);
  14. echo '
    ';
  15. /*Single out the last element of the array, pay attention to the difference with end()*/
  16. //echo array_pop($pics);
  17. /*First sort the array in reverse order by key value, and then single out the first element*/
  18. krsort($pics);
  19. echo array_shift($pics);
  20. echo '
    ' ;

  21. /*The value corresponding to the extension index of the pathinfo() function return value*/

  22. $res = pathinfo($pic); //5
  23. var_dump($res);
  24. echo $ res['extension'].'
    ';

  25. /*String interception, just take the last three digits*/

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

Copy code


Statement:
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