PHP: File extension using PHP built-in function

Posted: 2011/08/29 in Development, PHP

Came across this amazing, simple feature in PHP Strings: How to Get the Extension of a File by “Stoimen” where the problem of getting a file’s “extension” is solved simply.

Instead of: substr($filename, strrpos.....
use: pathinfo($filename, PATHINFO_EXTENSION)

Best part is that this uses PHP to get the extension of a file. As the author notes, this lets us rely on really smart people who have to do a good job.

EQUALLY great are the two comments (as of my posting this):

What I love about this simple, single post is that I learned about pathinfo, end, and have yet another tool in my SPL toolbelt. Awesome.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s