PHP file extension _ PHP Tutorial

Source: Internet
Author: User
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...

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.