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.
PHP - trim everything before the period
Moderator: General Moderators
Re: PHP - trim everything before the period
will you ever have more than one period like test.my.site.gif? Do you just want the file extension?
[text]/www/htdocs/inc
lib.inc.php
php
lib.inc[/text]
if you want the dot, $extension=".".$path_parts['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.0lib.inc.php
php
lib.inc[/text]
if you want the dot, $extension=".".$path_parts['extension'];