You can also try this -
$test = "aaa.bbb.ccc.gif";
$temp = explode('.', $test);
unset($temp[count($temp) - 1]);
echo implode('.', $temp);
O / p
aaa.bbb.ccc
strpos - find the position of the first occurrence of a substring in a string
You need to use strrpos
strrpos - find the position of the last occurrence of a substring in a string
$test = "aaa.bbb.ccc.gif";
$test = substr($test, 0, strrpos($test, "."));
echo $test;
O / p
aaa.bbb.ccc
source
share