If possible, using only standard PHP functions like substr(), strrpos(), strpos(), etc.
First, find the last position:
$last = strrpos($haystack, $needle); if ($last === false) { return false; }
From there, find the 2nd last:
$next_to_last = strrpos($haystack, $needle, $last - strlen($haystack) - 1);