我使用模型视图控制器和在我的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
}
例如:
if(strrev($url)[0]==='/') {
// the last character in the url is a slash
}
你有很多可能性:
有斜杠:
$url{strlen($url)-1} == '/'; (same as $url[strlen($url)-1] == '/';)
strrpos($a,'/') === strlen($a) -1