Php 警告:strpos():wordpress插件中的空指针
我得到这个错误: 警告:strpos():在……popularity-contest.php上出现空针 第2574行Php 警告:strpos():wordpress插件中的空指针,php,wordpress,function,plugins,wordpress-shortcode,Php,Wordpress,Function,Plugins,Wordpress Shortcode,我得到这个错误: 警告:strpos():在……popularity-contest.php上出现空针 第2574行 有人能帮我解决这个问题吗?如果在WP\u config.php中将WP\u DEBUG设置为false,警告应该消失。如果要修复它,请尝试以下操作: function akpc_is_searcher() { global $akpc; $referrer = parse_url($_SERVER['HTTP_REFERER']);
有人能帮我解决这个问题吗?如果在WP\u config.php中将WP\u 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;
}
许多PHP搜索函数使用术语“针”和“干草堆”作为其参数名,指示搜索内容和搜索位置
strpos
函数就是这样一个函数。“空指针”表示您已传入一个null或空值作为要查找的指针。这就像说“不搜索任何东西”,这对函数没有意义
要解决此问题,请检查作为指针传入的变量是否具有实际值。
empty
函数是一个很好的选择。第2574行
--您最好将您的文件分隔为一个较小的文件。您的代码工作正常!谢谢但是,遇到的新问题有:“警告:preg_replace():第2572行popularity-contest.php中的未知修饰符”“如何解决此问题?第2572行=$searchers=explode(“”,preg_replace(“\n | \r | \r\n | \r”,“”,$akpc->searcher_name));正则表达式模式必须用“/”括起来。试试这个:$searchers=explode(“”,preg|u replace(“/\n | \r | \r\n | \r/”,“”,$akpc->searcher_name))代码>看起来不错,谢谢!!真的很有帮助
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;
}