我已经检查了我的apache错误日志,并且看到了如下多个消息:
client 108.162.246.190] PHP Notice: Undefined offset: 4 in /var/www/html/search.php on line 142
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 5 in /var/www/html/search.php on line 142
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 5 in /var/www/html/search.php on line 143
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 6 in /var/www/html/search.php on line 142
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 6 in /var/www/html/search.php on line 143
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 7 in /var/www/html/search.php on line 142
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 7 in /var/www/html/search.php on line 143
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 8 in /var/www/html/search.php on line 142
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 8 in /var/www/html/search.php on line 143
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 9 in /var/www/html/search.php on line 142
[Tue Dec 31 00:17:48 2013] [error] [client 108.162.246.190] PHP Notice: Undefined offset: 9 in /var/www/html/search.php on line 143
围绕142-143行的代码如下所示(实际的142-143行是内爆的):
if ($nuorodoshut != NULL)
{
foreach ($nuorodoshut as $key => $nuorodahut)
{
$keywords = explode(' ', $qsvarus);
$title[$key] = preg_replace('/\b('.implode('|', $keywords).')\b(?![^<]*[>])/i', '<b>$0</b>', $title[$key]);
$infoo[$key] = preg_replace('/\b('.implode('|', $keywords).')\b(?![^<]*[>])/i', '<b>$0</b>', $infoo[$key]);
echo '<tr><td><h3>';
echo str_replace('<a href="/', '<a href="/host/', $nuorodahut->innertext) . '</h3>';
echo $aprasymashut[$key]->innertext . '<br>';
}
}
我只是无法处理此错误。任何帮助,将不胜感激
最佳答案
错误消息告诉您,当$title[$key]
为$infoo[$key]
-$key
时,没有5
和9
。如果这两个数组都应具有与$nuorodoshut
相同的索引,则在创建数组时出了点问题。
如果可以确定它们不应该包含这些元素,则在使用这些值之前,需要先进行检查,例如
$title[$key] = isset($title[$key]) ? preg_replace('/\b('.implode('|', $keywords).')\b(?![^<]*[>])/i', '<b>$0</b>', $title[$key]) : '';
$infoo[$key] = isset($infoo[$key]) ? preg_replace('/\b('.implode('|', $keywords).')\b(?![^<]*[>])/i', '<b>$0</b>', $infoo[$key]) : '';
关于php - PHP错误处理-未定义偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20850090/