Best way to remove trailing slashes in URLs with PHP

Solution 1:

You put rtrim in your answer, why not just look it up?

$url = rtrim($url,"/");

As a side note, look up any PHP function by doing the following:

  • http://php.net/functionname
  • http://php.net/rtrim
  • http://php.net/trim

(rtrim stands for 'Right trim')

Solution 2:

Simple and works across both Windows and Unix:

$url = rtrim($url, '/\\')