Reputation:
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
Reputation:
Try this,
$pathinfo = pathinfo('stack.over.flow.zip');
echo 'Extension: '.$pathinfo['extension'];
will produce:
Extension: zip
Function used: Pathinfo()
Upvotes: 0
Reputation: 6608
$a = explode('.', $filename );
echo end($a);
Functions used:
Alternative:
$last_three_chars = substr( $filename, -3 );
echo $last_three_chars ;
Upvotes: 2