duanhuo3392 2017-02-24 11:43
浏览 41

PHP - 解析新行日志

I have the following log:

#VERSION: 2.9 2017-02-24 10:03:39 channel_ping 1afcd2e2857045fe973e7ed036ea450c dfe17897d80b44f6901593364fc72b55 2479884 127.0.0.1 Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_11_6)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/56.0.2924.87%20Safari/537.36 https://test.com/ TEST-User-50187 42134f99b57240d19e05f760800a9dc6

I can read the content of this in PHP no problem which outputs:

#VERSION: 2.9 2017-02-24\t10:03:39\tchannel_ping\t1afcd2e2857045fe973e7ed036ea450c\tdfe17897d80b44f6901593364fc72b55\t2479884\t127.0.0.1\tMozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_11_6)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/56.0.2924.87%20Safari/537.36\thttps://test.com/\tTEST-User-50187\t42134f99b57240d19e05f760800a9dc6 """

I need to be able structure this into something like so:

array[0] = '2017-02-24'; array[1] = '10:03:39'; array[2] = 'channel_ping';

  • 写回答

3条回答 默认 最新

  • dr2898 2017-02-24 11:46
    关注

    You can explode your output:

    $arr = explode("\\t",$linesOf);
    

    Or if $linesOf already includes the \t as a normal string:

    $arr = explode("\t",$linesOf);
    

    Before I would make a substring to get rid of the "#VERSION: 2.9 " part...

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题