简体   繁体   English

Strpos不起作用

[英]Strpos not working

I need to see if the URL the user is currently on closely matches (So contains) the URL in the database. 我需要看到,如果用户是目前匹配的URL(所以包含)的URL数据库。 However strpos doesn't seem to be doing the job correctly. 但是,strpos似乎无法正确完成这项工作。

This is the code i'm using 这是我正在使用的代码

if(strpos($row['url'], $currenturl) === 0) {
    echo "YEAH!";
    return true;
}
echo "Current URL: ".$currenturl." Permission URL: ".$row['url']." Strpos ".strpos($row['url'], $currenturl)."<br>";

And this is the debug output. 这是调试输出。

Current URL: projects/projectview.php?whmcsid=0&id=4 Permission URL: projects/projectview.php?whmcsid=0 Strpos 当前网址:projects / projectview.php?whmcsid = 0&id = 4许可权网址:projects / projectview.php?whmcsid = 0 Strpos

So its not matching. 因此,它不匹配。 Any ideas? 有任何想法吗?

You have invalid order of arguments. 您的参数顺序无效。 strpos searches in haystack for a needle , so: strposhaystack搜索needle ,因此:

if(strpos($currenturl, $row['url']) === 0) {
    // code here
}

To get to know the substring is absent, you must use, 要了解该子字符串不存在,您必须使用

   ===FALSE

as 0 may also indicate the starting position of the substring. 为0也可能表示子字符串的起始位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM