Reputation: 363
I have written a preg_match
code to remove all trailing slashes and that is as follows..
preg_replace("/(\/?)+$/",'',$_SERVER['REQUEST_URI']);
will this hold good any time.
what is the alternatives to remove all trailing slashes...
consider that the users would give sitename.com/folder/ or sitename.com/folder// or sitename.com/folder
Upvotes: 1
Views: 928
Reputation: 1383
See bellow:
<?php
$url = "http://example.co/4569128/removing-all-trailing-slashes-in-an-url/"
$newUrl = rtrim($url','/');
?>
Output : http://example.co/4569128/removing-all-trailing-slashes-in-an-url
------------------------------------------------------------------------
Upvotes: 0