PHP 8.4.24 Released!

Voting

: min(eight, one)?
(Example: nine)

The Note You're Voting On

ivijan dot stefan at gmail dot com
12 years ago
I found that the function end() is the best for finding extensions  on file name. This function cleans backslashes and takes the extension of a file.

<?php
private function extension($str){
    $str=implode("",explode("\\",$str));
    $str=explode(".",$str);
    $str=strtolower(end($str));
     return $str;
}

// EXAMPLE:
$file='name-Of_soMe.File.txt';
echo extension($file); // txt
?>

Very simple.

<< Back to user notes page

To Top