简体   繁体   English

删除网址中的所有结尾斜杠

[英]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_match代码以删除所有尾随的斜杠,如下所示。

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 认为用户会给出sitename.com/folder/或sitename.com/folder//或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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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