我需要查看用户当前所在的 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:projects/projectview.php?whmcsid=0 Strpos
所以它不匹配。有什么想法吗?
您的参数顺序无效。
strpos
在 haystack
中搜索 needle
,所以:
if(strpos($currenturl, $row['url']) === 0) {
// code here
}
要知道子字符串不存在,您必须使用,
===FALSE
as 0 也可以表示子串的起始位置。