Alperen Özdemir Alperen Özdemir - 6 months ago 31
PHP Question

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.

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

Functions used:

Alternative:

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

substr()