Intercepting file extensions in five different ways-PHP source code

Source: Internet
Author: User
Truncate the file suffix in five different ways
/*** Write five methods to get the file suffix name, a very easy exam question */$ filename = 'www character substr (strrchr ($ filename ,'. '), 1); // Intercept first. and then use substr to capture the string starting from 1. then, you can use the pathinfo function to arrange the array $ arr = pathinfo ($ filename ); echo $ arr ['extension']; // method 3 use the strrpos function to find the last one. and then use substr to capture the length of echo substr ($ filename, (strrpos ($ filename ,'. ') + 1); // use arrays to obtain $ ar = explode ('. ', $ filename); echo arra Y_pop ($ ar); // you can use the regular expression echo (preg_replace ('/. *. (. * [^.]. *) */iU ',' \ 1', $ filename); // This function is very useful. For more information, see.

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.