Php get file name extension-PHP source code

Source: Internet
Author: User
Extension file suffix gif * extension filewww.111cn.net.gif; echogetfix ($ file); The obtained value is gif. This method is the simplest and most practical. Let's get the script ec (2); script

In php, there are two functions: end () and current (). The former is to read the last element value of the array, and the latter is to read the first value of the array,
In this case, we can see that I use an endpoint to read the 111cn.gif file suffix gif.
*/
$ File = 'www.111cn.net.gif ';
Echo getfix ($ file );

// The obtained value is gif. This method is the simplest and the most practical. Let's take a look at method 2. This method reads the extension using substr.

$ File named 'aaa.gif ';
Echo substr ($ file, strpos ($ file, '.') + 1 );

// Method 3 Use Arrays

$ File = '111cn.gif ';
$ D111cn = explode ('.', $ file );
Echo $ d111cn [count ($ d111cn)-1];

Function getfix ($ l1 ){
Return end (explode ('.', $ l1 ));
}

// This article was originally posted on www.111cn.net and indicated the source

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.