How to display file extension PHP file extension get function

Source: Internet
Author: User
Tags strtok
Copy CodeThe code is as follows:


$file = "/home/lvyaozu/backup_20080115.txt";
for ($i =1; $i < 6; $i + +) {
$func = ' Get_file_ext_ '. $i;
Var_dump ($func ($file));
}
function Get_file_ext_1 ($file) {
Return Strtolower (Trim (substr (STRRCHR ($file, '. '), 1)));
}
function Get_file_ext_2 ($file) {
Return Strtolower (Trim (PathInfo ($file, pathinfo_extension));
}
function Get_file_ext_3 ($file) {
Return Strtolower (Trim (substr ($file, Strrpos ($file, '. ') +1)));
}
function Get_file_ext_4 ($file) {
Return Strtolower (Trim (Array_pop (Explode ('. ', $file)));
}
function Get_file_ext_5 ($file) {
$tok = Strtok ($file, '. ');
while ($tok!== false) {
$return = $tok;
$tok = Strtok ('. ');
}
Return Strtolower (Trim ($return));
}
?>
This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/lvyaozu/archive/2009/06/03/4237628.aspx

The above describes how to display the file extension php file extension Get functions, including how to display the file extension aspects, I hope that the PHP tutorial interested in a friend helpful.

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