PHP How to get file extension _php tutorial

Source: Internet
Author: User

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 ...

  • Related Article

    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.