php 警告:strpos():......wordpress 插件中的空针

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26325407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:17:03  来源:igfitidea点击:

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

phpwordpress

提问by user57139

I get this error :

我收到此错误:

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

警告:strpos():第 2574 行的 ......popularity-contest.php 中的空针

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?

有人可以帮我解决这个问题吗?

采纳答案by Vlad Cazacu

The warning should go away if you set WP_DEBUG to false in wp_config.php. If you want to fix it, try the following:

如果您在 wp_config.php 中将 WP_DEBUG 设置为 false,警告应该会消失。如果您想修复它,请尝试以下操作:

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;
}

回答by Dancrumb

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.

一堆 PHP 搜索函数使用术语“needle”和“haystack”作为它们的参数名称,指示要查找的内容以及查找的位置。

The strposfunction 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.

strpos功能是这样的功能。“空针”表示您传入了一个空值或空值作为要查找的针。这就像说“什么都不搜索”对函数没有意义。

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

要解决此问题,请检查您作为针传入的变量是否具有实际值。该empty功能是一个不错的选择。