php - 使用“list”函数时的PHP未定义偏移量消息
问题描述
今天早上,当我点击广告后,我的网站上出现了这个错误
我试过查看代码,但似乎没有发现任何问题
if (!function_exists('adforest_extarct_link')) {
function adforest_extarct_link($string) {
$arr = explode('|', $string);
list($url, $title, $target, $rel) = $arr; /* This is line 148 */
$rel = urldecode(adforest_themeGetExplode($rel, ':', '1'));
$url = urldecode(adforest_themeGetExplode($url, ':', '1'));
$title = urldecode(adforest_themeGetExplode($title, ':', '1'));
$target = urldecode(adforest_themeGetExplode($target, ':', '1'));
return array("url" => $url, "title" => $title, "target" => $target, "rel" => $rel);
}
这是错误消息
未定义的偏移量:第 148 行 /customers/7/6/1/corpersmarket.com/httpd.www/wp-content/themes/adforest/inc/theme_shortcodes/short_codes_functions.php 中的 3
它实际上有 3 行错误:
Notice: Undefined offset: 1 in /customers/7/6/1/corpersmarket.com/httpd.www/wp-content/themes/adforest/inc/theme_shortcodes/short_codes_functions.php on line 148
Notice: Undefined offset: 2 in /customers/7/6/1/corpersmarket.com/httpd.www/wp-content/themes/adforest/inc/theme_shortcodes/short_codes_functions.php on line 148
Notice: Undefined offset: 3 in /customers/7/6/1/corpersmarket.com/httpd.www/wp-content/themes/adforest/inc/theme_shortcodes/short_codes_functions.php on line 148
解决方案
然而,
您list
预计至少有 4 个参数 - 但您的$arr
数组只有 1 个。所以以下三个是空的。(记住数组从 0 开始)。因此,您$string
不包含使功能按预期工作的|
字符。explode
解决方法:
原来的:
$arr = explode('|', $string);
list($url, $title, $target, $rel) = $arr; /* This is line 148 */
变成:
$arr = array_pad(explode('|', $string), 4, null);
list($url, $title, $target, $rel) = $arr;
这是做什么的:
填充数组以包含至少 4 个值;这样这些list
值将始终被填充,即使它们可能仍然为空。
推荐阅读
- ios - 在 iOS Swift 中获取 Facebook 封面照片 URL
- visual-studio - 如何创建 Visual Studio 安装项目运行其他安装程序
- java - Servlet 写入文件但不写入 servletOutputStream
- python - 从python中的字符串中获取特定的子字符串
- elisp - find-lisp-object-file-name 返回错误值
- gitkraken - 推送错误 GitKraken
- android - 如何使用我们自己的应用程序添加新指纹?
- sql - XML 嵌套/分组的 SQL 查询
- scala - 如何使用if else表达式在scala中分配不同的变量名
- python-3.x - Python Discord Bot,需要服务器 ID