A nice solution to remove safely the last /
is to use
$string = rtrim($string, '/');
rtrim()
removes all /
s on the right side of the string when there is one or more.
You can also safely add exactly one single /
at the end of an URL:
$string = rtrim($string, '/').'/';
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…