Here's a quick method to make sure a string has exactly 0 or 1 slash at its end.

function trailSlash($s, $force = true)
{
     return rtrim($s, '/').($force ? '/' : '');
}

// Usage :
// $url = trailSlash($url); makes sure $url ends with /
// $url = trailSlash($url, false); makes sure it doesn't