Hi all

i am a bit stuck lol
I am trying to get the file extention from a url say

in the data base the full link will be there, i am looking for a function that will take the full url
take ".zip" and then will output "(file type = ZIP )"

some help would be great


These functions seem to be along the line of what you're looking for:

  • strrpos
    Find the position of the last occurrence of a substring in a string
  • substr
    Return part of a string

So, you could use strpos to find where the last . character occurs in the string example.org/some_file.zip, and then use substr to get the part of the string that comes after that character (which would be zip in this case).

Hope that helps!

You can try with explode() function.

$str = 'yoursite.com/file.zip';
$ext = end(explode('.', $str));
echo 'file type = '. strtoupper($ext);     // file type = ZIP
Member Avatar

The function you need is pathinfo:

$bits = pathinfo('/path/file.zip');
echo $bits['extension'];

So for your case:

$bits = pathinfo($url);
echo "file type = " .strtoupper($bits['extension']);

ahh thanks that worked the trick

Member Avatar

We solved? If so, mark as solved.