0

Hi all

i am a bit stuck lol
I am trying to get the file extention from a url say
yoursite.com/file.zip

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

cheers

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by diafol
0

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!

Edited by TySkby

0

Hy
You can try with explode() function.
Example:

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

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']);

Edited by diafol

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.