php - 如何在正则表达式中修复此错误“未定义的偏移量:”?
问题描述
对于数据中的每一行,我都会收到此错误。所以大约 500 次,但每次都有另一个未定义的偏移量。这是我的代码:
$fl_array = preg_grep('/^\d+\s('. $SelectedTime .':)\d+/', explode("\n", $finalLog));
$count = count($fl_array);
for ($x = 0; $x < $count; $x++)
{
echo "$fl_array[$x] \n";
}
解决方案
如此处所写 - http://php.net/manual/en/function.preg-grep.php:Returns an array indexed using the keys from the input array.
所以您的密钥可能有问题:
if (isset($fl_array[$x])) {
echo "$fl_array[$x] \n";
}
推荐阅读
- php - How to convert a mysql json field to a javascript Object with laravel?
- python - 使用opencv在鼻子和眼睛轴上旋转图像
- ruby - 继承前或后挂钩到子类
- json - Haskell 构建简单的 JSON 解析器
- oracle - 在 Oracle 中删除模式上的所有对象
- jquery - 试图以编程方式在溢出 div 中滚动,但 $('el').scrollLeft() 总是返回零
- javascript - 从 Google Apps 脚本查询 Google Sheet
- javascript - 从 Nodemailer 的 post 请求中获取用户的信息
- c - STM32F103RB Nucleo收发usart
- c# - 尽管以管理员身份运行命令提示符,但无法打开服务控制管理器