Is it possible to remove the trailing slash ( / ) from a string using PHP?

Accepted Answer

Sure it is, simply check if the last character is a slash and then nuke that one.

if(substr($string, -1) == '/') {
    $string = substr($string, 0, -1)

Another (probably better) option would be using rtrim() - this one removes all trailing slashes:

$string = rtrim($string, '/');
Written by ThiefMaster
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the community.
It is licensed under cc-wiki