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?