Page 1 of 1

PHP - trim everything before the period

Posted: Sun Feb 12, 2012 2:06 pm
by cjkeane
Hi everyone, I'm wondering if there is a way to trim everything before the period in a variable. For e.g.:

variable = test.jpg
new variable = .jpg

Thanks.

Re: PHP - trim everything before the period

Posted: Sun Feb 12, 2012 6:28 pm
by Eric!
will you ever have more than one period like test.my.site.gif? Do you just want the file extension?

Code: Select all

$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');

echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
[text]/www/htdocs/inc
lib.inc.php
php
lib.inc[/text]
if you want the dot, $extension=".".$path_parts['extension'];