How does php get the file suffix?

Source: Internet
Author: User
How does php obtain the file suffix & nbsp; I haven't written a blog for a long time, and people are getting lazy. this is a technical taboo, everything is always a constant "word", and I hope to stick to the blog in the future. This time, I will write a php function to get the file suffix! & Nbsp; & php how to get the file suffix

I haven't written a blog for a long time, and people become more and more lazy. this is a technical taboo. I hope I can continue to stick to my blog in the future. This time, I will write a php function to get the file suffix!

1. string truncation

function getFileExt($file){try{if(empty($file))return false;$pos=strrpos($file, ".");if(!$pos) return false;return substr($file, $pos+1);}catch(Exception $e){//}return false;}

2. use regular expressions to separate

function getFileExt($file){try{if(empty($file))return false;if($arr=preg_split("/\./",$file)){return array_pop($arr);}}catch(Exception $e){//}return false;}

Is there any better way?


1st floor Love _ Coder4 days ago
How is two empty?

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.