Ech*_*ara 3 php 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
Run Code Online (Sandbox Code Playgroud)
您可以通过先获取整个 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
}
Run Code Online (Sandbox Code Playgroud)