The trim function returns the trimmed string. It doesn't modify the original. Your third line should be:
trim
$url = trim($url, '/');
This can be done in one line...
echo trim($_SERVER['REQUEST_URI'], '/');
You need to do:
You also should just do
echo $url;
It is faster.