How PHP obtains the file name extension
In the work, often encounter need to get the file extension, here I give you the following several methods. (Welcome to criticize)
Method One
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 Two
function Getfileextend_2 ($fileName) {
$extend = PathInfo ($fileName);
$extend = Strtolower ($extend [' extension ']);
if (is_string ($extend)) {
return $extend;
}
return false;
}
?>
Method Three
function Getfileextend_3 ($fileName) {
$extend =explode (".", $fileName);
$va =count ($extend)-1;
$extend = $extend [$va];
if (is_string ($extend)) {
return $extend;
}
return false;
}
?>
http://www.bkjia.com/PHPjc/845131.html www.bkjia.com true http://www.bkjia.com/PHPjc/845131.html techarticle PHP How to get the file extension in the work, often encountered need to get the file extension, here I give you the following several methods. (Welcome to criticize) method a function getf ...