如何删除多个斜线的URI与'preG'或'的.htaccess“ [英] how to remove multiple slashes in URI with 'PREG' or 'HTACCESS'
本文介绍了如何删除多个斜线的URI与'preG'或'的.htaccess“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除多个斜线的URI与'preG或.htaccess的
how to remove multiple slashes in URI with 'PREG' or 'HTACCESS'
site.com/edition/new /// - > site.com/edition/new /
site.com/edition/new/// -> site.com/edition/new/
site.com/edition ///新的/ - > site.com/edition/new /
site.com/edition///new/ -> site.com/edition/new/
感谢
推荐答案
使用正则表达式的加号 +
是指一个或一个以上的previous的发生字符。因此,我们可以在preg_replace添加它通过只是其中之一来替换一个或多个 /
发生
using the plus symbol +
in regex means the occurrence of one or more of the previous character. So we can add it in a preg_replace to replace the occurrence of one or more /
by just one of them
$url = "site.com/edition/new///";
$newUrl = preg_replace('/(\/+)/','/',$url);
// now it should be replace with the correct single forward slash
echo $newUrl
这篇关于如何删除多个斜线的URI与'preG'或'的.htaccess“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文