Warning: strpos(): Empty needle in ......wordpress Plugin

user57139 picture user57139 · Oct 12, 2014 · Viewed 26.5k times · Source

I get this error :

Warning: strpos(): Empty needle in ......popularity-contest.php on line 2574

function akpc_is_searcher() {
        global $akpc;
        $referrer = parse_url($_SERVER['HTTP_REFERER']);
        $searchers = explode(' ', preg_replace("\n|\r|\r\n|\n\r", ' ', $akpc->searcher_names));
        foreach ($searchers as $searcher) {
                if (strpos($referrer['host'], $searcher) !== false) {
                        return true;
                }
        }
        return false;
}

Can someone please help me to fix this problem?

Answer

Dancrumb picture Dancrumb · Oct 12, 2014

A bunch of PHP search functions use the terms "needle" and "haystack" as their parameter names, indicating what is sought and where to seek it.

The strpos function is such a function. "Empty needle" means that you have passed in a null or empty value as the needle to look for. This is like saying "search for nothing" which doesn't make sense to the function.

To fix this, check that the variable that you're passing in as the needle has an actual value. The empty function is a good choice for that.