PHP循环中未定义的偏移量错误

杰伊·道格(Jay Dogg)

我正在查看我的httpd错误日志,并一遍又一遍地注意到此错误

未定义的偏移量:第43行的/usr/home/*****/*****/*****/*****/index.php中的1。

我希望有人可以查看我的代码,看看他们看到会导致此错误的任何问题

<?php $files = scandir('movies/');
            foreach($files as $file) {
              if ($file === '.' or $file === '..') continue;
              $t = str_replace("-", " ", $file);
              $section = explode(';', $t);
              $section = explode('.', $section[1]);
              $t = explode(';', $t);
              $t = $t[0]; 

出现错误的行是

$section = explode('.', $section[1]);

该代码正在网站上运行,但出现错误

耶戈

碰巧的是,由于爆炸后,你有阵只能用[0]钥匙可能,这意味着你有没有;在你$t的前行和整体$t进入第一个$section任务。

永远不要假设您将始终在代码开发期间始终拥有完全正确的数据。您正在为自己设置陷阱。我建议解决方案接近以下内容:

$section = explode(';', $t);
$section = explode('.', count($section) > 1 ? $section[1] : $section[0]);

或者

$section = explode(';', $t);
if(count($section) === 0) {
    // debug code, warnings, reports, Exceptions etc.
} else {

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章