PHP gets the file name extension

Source: Internet
Author: User
<?php   $url = ' dir/upload.image.jpg ';      function GetExt1 ($url) {      return strrchr ($url, '. ');   }      function GetExt2 ($url) {      return substr ($url, Strrpos ($url, '. '));   }      function GetExt3 ($url) {      $a = explode ('. ', $url);      return Array_pop ($a);   }      function GetExt4 ($url) {      $p = PathInfo ($url);      return $p [' extension '];   }      function GetExt5 ($url) {      return Strrev (substr (Strrev ($url), 0, Strpos (Strrev ($url), '. ')));   }      $s = GETEXT5 ($url);   Echo $s;? >

  

Note: 1, STRRCHR ()-function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string. Otherwise, false is returned.

2, Array_pop (): Deletes the last element in the array. Return value: Returns the last value of the array. If the array is empty, or is not an array, NULL is returned.

3, PathInfo () returns an associative array containing information about path .

Includes the following array elements: [DirName], [basename], [extension]

PHP gets the file name extension

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.