How does PHP obtain the file extension. How to obtain the file extension in PHP is often used at work. here I will summarize the following methods. (Welcome to criticize and correct) method 1 functiongetF PHP how to obtain the file extension
During work, you often encounter file extensions. here I will summarize the following methods. (Welcome to criticize and correct)
Method 1
Function getFileExtend_1 ($ fileName ){
$ Retval = "";
$ Pt = strtpos ($ fileName ,".");
If ($ pt ){
$ Retval = substr ($ fileName, $ pt + 1, strlen ($ fileName)-$ pt );
}
If ($ retval! = ""){
Return $ retval;
}
Return false;
}
?>
Method 2
Function getFileExtend_2 ($ fileName ){
$ Extend = pathinfo ($ fileName );
$ Extend = strtolower ($ extend ['extension']);
If (is_string ($ extend )){
Return $ extend;
}
Return false;
}
?>
Method 3
Function getFileExtend_3 ($ fileName ){
$ Extend = explode (".", $ fileName );
$ Va = count ($ extend)-1;
$ Extend = $ extend [$ va];
If (is_string ($ extend )){
Return $ extend;
}
Return false;
}
?>
In my work, users often encounter file extensions. here I will summarize the following methods. (Welcome to criticize and correct) Method 1: function getF...