Is it possible to remove the trailing slash /
from a string using PHP?
5 Answers
251
votes
27
votes
Long accepted, however in my related searches I stumbled here, and am adding for "completeness"; rtrim()
is great, however implemented like this:
$string = rtrim($string, '/\\'); //strip both forward and back slashes
It ensures portability from *nix to Windows, as I assume this question pertains to dealing with paths.
5
votes
2
votes