doulan9419 2013-04-09 03:33
浏览 92

直接在数组中保存控制台应用程序输出

How can we do further comparision or computation on the output of a console application. As I believe it is in ASCII form. I have called the console application in php which gives a huge amount of numeric datas. I want that data to be saved on an array and not in a txt file as the process of reading and writing a file takes time I want it to directly save it in an array. I used exec($command,$result) but I cannot get the result to be saved in proper form. My output is as shown below:

    Columns 1 through 7

0.1373    0.0414    0.0541    0.1342    0.5606    0.5293    0.1652

 Columns 8 through 14

0.0341    0.0396    0.0633    0.0778    0.0289    0.0654    0.0752

Columns 15 through 21

0.3055    0.4602    0.0631    0.0360    0.0188    0.0497    0.0228...........

I dont want the columns line to be saved in the array and I want each element in column to be saved in different index of array. Eg array[1]=0.1373 and array [2]=0.414.

  • 写回答

2条回答 默认 最新

  • douwei1408 2013-04-09 03:36
    关注

    My suggestion would be a simple regular expression that you run on each line of the output:

    if (preg_match_all('/\d+\.\d+/', $line, $matches)) {
        print_r($matches[0]);
    }
    

    If the expression matches, you will have an array of results that you can use for further processing. The output for the first line that matches from your post:

    Array
    (
        [0] => 0.1373
        [1] => 0.0414
        [2] => 0.0541
        [3] => 0.1342
        [4] => 0.5606
        [5] => 0.5293
        [6] => 0.1652
    )
    
    评论

报告相同问题?

悬赏问题

  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问