Use this if you're stuck on an old version of PHP

function rstrstr($haystack, $needle) {
    $idx = strrpos($haystack, $needle);
    if ($idx !== false) $haystack = substr($haystack, 0, $idx);
    return $haystack;
}