开发者

removing all trailing slashes in an url

开发者 https://www.devze.com 2023-02-02 10:23 出处:网络
I have written a preg_match code to remove all trailing slashes and that is as follows.. preg_replace(\"/(\\/?)+$/\",\'\',$_SERVER[\'REQUEST_URI\']);

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 s开发者_开发问答itename.com/folder// or sitename.com/folder


You can do:

$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

------------------------------------------------------------------------
0

精彩评论

暂无评论...
验证码 换一张
取 消