Jump to content

getting file's extention


calvin182

Recommended Posts

get the URL or the address then take the last 4 charactorslike this:$file = "/folder/file.txt";$extension = substr($file, strlen($file) - 4);$extension will be .txt(with jpeg you will not have the dot)

Link to comment
Share on other sites

FINE, were take the easy way out... I was trying to have fun!

<?php$path_parts = pathinfo('/www/htdocs/index.html');print $path_parts['extension'];?>

if you need more than the ending like: path?arg=value#anchorthen I would go with parse_url ( string url )this will output:Array( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor)but if you need from the dot on, you will have to break it at the . (dot) and take the $var[1]

Link to comment
Share on other sites

I know your problem is already solved, but this may be an easier way:

$file_name="12345.abcd";preg_match('/\.[^.]+$/', $file_name, $ext);

So the extension there would be ".abcd" and the Preg_match would send it out as an array, so use $ext[0].

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...