我需要查看用户当前所处的 URL 是否与数据库中的URL紧密匹配(所以包含)。然而,strpos似乎没有正确地完成这项工作。
这是我正在使用的代码
if(strpos($row['url'], $currenturl) === 0) {
echo "YEAH!";
return true;
}
echo "Current URL: ".$currenturl." Permission URL: ".$row['url']." Strpos ".strpos($row['url'], $currenturl)."<br>";这是调试输出。
当前URL: projects/projectview.php?whmcsid=0&id=4权限URL: project/projectview.php?whmcsid=0 Strpos
所以它不匹配。有什么想法吗?
发布于 2017-02-14 18:43:37
你的论点顺序无效。strpos在haystack中搜索needle,因此:
if(strpos($currenturl, $row['url']) === 0) {
// code here
}发布于 2017-02-14 18:43:45
要知道子字符串不存在,必须使用
===FALSEas 0也可以指示子字符串的起始位置。
https://stackoverflow.com/questions/42233796
复制相似问题