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 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题