Several ways to get file suffix names in PHP

Source: Internet
Author: User

There are a number of ways to get file suffixes, which can be summed up in 7, 8, basically the principle is divided into two kinds. The first one: Get the last "." in the filename. , and then intercept; the second: Use the explode to "." To split the number of groups, and then take the last value in the array.

Specific implementation of the source code reference:

$file 1 = ' e:/ddd/ww/file.doc.zip ';

$file 2 = ' e:/ddd/ww/file.jpg.png ';

$suffix 1 = end (Explode ('. ', $file 1)); First the filename with "." Split the number of groups, and then use the End function to take the last value of the array

$suffix 2 = substr ($file 2, Strrpos ($file 2, '. ') +1); Strrpos first calculates the last "." , and then use substr to intercept

echo $suffix 1. '. $suffix 2;

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.