php checking if the last character is a ‘/’ if not then tack it on

You might be overthinking it. While the substr() method will work perfectly it might be simpler to use rtrim() to remove any trailing slashes and then add one on.

$path = rtrim($path, "") . "";

Caution: this will trim multiple trailing forward slashes. so .////// becomes ./

Leave a Comment