Найти 3-ий слеш в переменной и обрезать после него все остальное (php) на примере урла текущей страницы $APPLICATION->GetCurDir()

<?
//$URL = $APPLICATION->GetCurDir();

function cut_str_by_char(string $str, int $char_number = 3, string $char = '/'): string
{
    $positions = [];
    $offset = 0;
    do {
        $pos = strpos($str, $char, $offset);
        if ($pos !== false) {
            $positions[] = $pos;
            $offset = $pos + 1;
        }
    } while ($pos !== false);

    return isset($positions[$char_number - 1])
        ? substr($str, 0, $positions[$char_number - 1] + 1)
        : $str;
}

$URL = cut_str_by_char($APPLICATION->GetCurDir());
echo $URL;
?>


где $char_number = 3 - после какого слеша обрезать

Возврат к списку


-----
-----