gpt4 book ai didi

PHP : Check if the URL contains slash at the end

转载 作者:行者123 更新时间:2023-12-03 23:23:04 25 4
gpt4 key购买 nike

我正在使用 Model View Controller ,并且在我的 URL 中,我需要在 URL 的末尾添加斜线。如何检查它是否有斜线?

http://localhost/tabulation/event/event_name/<--I need to check this slash

$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url. '/');
$url = explode('/', $url);
//if($url[2] has no backslashes then execute the condition

最佳答案

您可以通过先获取整个 url 然后获取最后一个字符来实现这一点

$getWholeUrl = "http://".$_SERVER['HTTP_HOST']."".$_SERVER['REQUEST_URI']."";

//The output would be
/*
http://localhost/tabulation/event/event_name/
*/

if(substr($getWholeUrl , -1)=='/'){
//Add your condition here

}

关于PHP : Check if the URL contains slash at the end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39598867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com