public static function subStringBeforeLast($haystack, $needle, $n = 1)
    {
        while ($n>0) {
            $haystack = substr($haystack, 0, strrpos($haystack, $needle));
            $n--;
        }
        return $haystack;
    }