Warning: strpos (): empty needle in ... wordpress Plugin
I am getting this error:
Warning: strpos (): Empty needle in ...... popular-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 anyone help me to solve this problem?
source to share
The warning should go away if you set WP_DEBUG to false in your wp_config.php file. If you want to fix the error, try the following:
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 ( ! empty($searcher) && strpos($referrer['host'], $searcher) !== false) {
return true;
}
}
return false;
}
source to share
PHP search function letter uses the terms "needle" and "haystack" as parameter names indicating what to look for and where to look.
A function strpos
is such a function. "Empty needle" means that you have passed zero or empty as the search needle. It's like saying "look for nothing" that doesn't make sense for a function.
To fix this, make sure the variable you are passing as a needle has an actual value. The function empty
is a good choice for this.
source to share