Jak usunać "/" ze stringa

0

Po wykonaniu takiego zadania:

    public static function getRequestURI() {
        return $_SERVER['REQUEST_URI'];
    }

Otrzymuje:

/~adza/portal/

W rezultacie chce otrzymywać coś takiego:

/~adza/portal

Jak usunać "/" z tego stringa wiadomo, że nie chce usuwać wszystkich tylko ten ostatni.

Próbowałem użyć czegoś takiego ale usuwa mi wszystkie:

 $string = str_replace('/', '', $string);

Pozdrawiam.

1
$str = "ABCD/";
$fixedStr = substr($str,-1) === '/' ? substr($str, 0, -1) : $str;
$str2 = "ABCD";
$fixedStr2 = substr($str2,-1) === '/' ? substr($str2, 0, -1) : $str2;

echo $fixedStr;
echo $fixedStr2;
0

Problem rozwiązałem w ten sposób :

$url = rtrim($url, '/'); 

Co myślicie?

1

Może tak:

 $string = "/~adza/portal/";

$rok = substr($string, 0, (strlen($string) - 1));
0
<?php
$string = '/~adza/portal/';
echo rtrim($string,'/');

1 użytkowników online, w tym zalogowanych: 0, gości: 1