A simple PHP function to determine a file’s extension.
fileExt()
function fileExt(path) {
return path.substr(path.lastIndexOf('.') + 1);
}
Sample Output
| Input | Output() |
|---|---|
| file.ext | ext |
| /folder/subfolder/file.ext | ext |
| file.bak.ext | ext |
A simple PHP function to determine a file’s extension.
function fileExt(path) {
return path.substr(path.lastIndexOf('.') + 1);
}
| Input | Output() |
|---|---|
| file.ext | ext |
| /folder/subfolder/file.ext | ext |
| file.bak.ext | ext |
genious man… just when i thought reversing the string then find the first occurrence of ‘.’ … i thought search in google… and i get what i need…
thanks again.. for publishing this little code…
That’s a good script but here’s another one. It takes some people a while to understand that substr function so I wrote another one for the light heads. (I was a light head too so I know how it is)