dongtan7351 2012-09-21 10:11
浏览 18
已采纳

爆炸数组结果和回声。

Have been working on a small project, and have gotten stuck at a part that I am trying to get working. Not sure if I am taking the wrong type of approach for it, and there is a better way, but here we go.

I have data in a text file that is written and read to. example: (values are separated by a \t)

S1684    This is a status    share   20/9/2012           share;

What I am doing is searching the file, and returning anything that matches as a part of the array. I have the search working fine, and can return each line that contains the search query, only problem is exploding the results so that I can properly format what I return. This is the main chunk that deals with it.

if(preg_match_all($pattern, $data, $matches)){
       echo "<h3>Results:</h3>";

       echo implode("<p>
", $matches[0])."</p>";

       foreach ($matches as &$value) {
        $date =0;
         list($statusCode, $status, $share, $date, $like, $comment, $share) = explode("\t", $date);

         echo "<h4>Status:".$status."</h4>";
         echo "<h4>Status Code:".$statusCode."</h4>";
       }

    }

The error I receive are undefined offset errors, so how exactly would I be able to explode (or split the array result in any other way) to echo it properly?

Any help is much appreciated thanks.

  • 写回答

1条回答 默认 最新

  • dongtuo6562 2012-09-21 10:28
    关注

    Shouldn't it be explode("\t", $value); instead of explode("\t", $date);

    You are using $value for holding the current value of the array during iteration. $date is always being assigned 0 in the iteration, and trying to explode it will be causing the error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)