How can I get file extensions with JavaScript?

Newer Edit: Lots of things have changed since this question was initially posted – there’s a lot of really good information in wallacer’s revised answer as well as VisioN’s excellent breakdown Edit: Just because this is the accepted answer; wallacer’s answer is indeed much better: return filename.split(‘.’).pop(); My old answer: return /[^.]+$/.exec(filename); Should do it. … Read more

How to get a file’s extension in PHP?

People from other scripting languages always think theirs is better because they have a built-in function to do that and not PHP (I am looking at Pythonistas right now :-)). In fact, it does exist, but few people know it. Meet pathinfo(): $ext = pathinfo($filename, PATHINFO_EXTENSION); This is fast and built-in. pathinfo() can give you … Read more

Extracting extension from filename in Python

Use os.path.splitext: >>> import os >>> filename, file_extension = os.path.splitext(‘/path/to/somefile.ext’) >>> filename ‘/path/to/somefile’ >>> file_extension ‘.ext’ Unlike most manual string-splitting attempts, os.path.splitext will correctly treat /a/b.c/d as having no extension instead of having extension .c/d, and it will treat .bashrc as having no extension instead of having extension .bashrc: >>> os.path.splitext(‘/a/b.c/d’) (‘/a/b.c/d’, ”) >>> os.path.splitext(‘.bashrc’) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)