简体   繁体   中英

removing all trailing slashes in an url

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

你可以做:

$path = rtrim($path','/');  
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

------------------------------------------------------------------------

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM