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
    )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型