【问题标题】:Warning: strpos(): Empty needle in ......wordpress Plugin [closed]警告:strpos():......wordpress插件中的空针[关闭]
【发布时间】:2014-12-07 03:46:24
【问题描述】:

我收到此错误:

警告:strpos(): Empty needle in ......popularity-contest.php on 第 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;
}

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

【问题讨论】:

  • on line 2574 -- 你最好把你的文件分成一个更小的文件。

标签: php wordpress function plugins wordpress-shortcode


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    如果您在 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;
    }
    

    【讨论】:

    • 您的代码运行良好!谢谢!但是遇到的新问题是:“Warning: preg_replace(): Unknown modifier '' in popular-contest.php on line 2572” 这个问题怎么解决?
    • 第 2572 行 = $searchers = explode(' ', preg_replace("\n|\r|\r\n|\n\r", ' ', $akpc->searcher_names));
    • 正则表达式模式必须包含在“/”中。试试这个:$searchers = explode(' ', preg_replace("/\n|\r|\r\n|\n\r/", ' ', $akpc->searcher_names));
    • 看起来不错,谢谢!!真的很有帮助
    猜你喜欢
    • 1970-01-01
    • 2015-04-12
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多