user5717177
user5717177

Reputation:

PHP Parsing From Right

I have a string like $filename = "stack.over.flow.zip" and I want to parse it and take just "zip" part from the string. I spend 3 hours on php.net. However, I couldn't found any method. By the way, there is not just a string, there are lots of variables.

Upvotes: 1

Views: 58

Answers (2)

user4579153
user4579153

Reputation:

Try this,

$pathinfo = pathinfo('stack.over.flow.zip');
echo 'Extension: '.$pathinfo['extension'];

will produce:
Extension: zip

Function used: Pathinfo()

Upvotes: 0

Akhilesh B Chandran
Akhilesh B Chandran

Reputation: 6608

$a = explode('.', $filename );
echo end($a);

Functions used:

Alternative:

$last_three_chars = substr( $filename, -3 );
echo $last_three_chars ;

substr()

Upvotes: 2

Related Questions