fork download
  1. <?php
  2.  
  3. $re = "/^([a-z]+\\s+[a-z]\\d+(?:,\\d+)+)\\s*(\\S+)\\s*([\\d:\\s]+\\d)\\s*([^\\/]+)\\s+\\/\\s+([^\\/]+)\\s+\\/\\s+([^\\/]+)\\s+$/mi";
  4. $str = "DER V3,0,0,3323 Xkisjd 2014 02 25 05:23 PGM / RUN BY / DATE \nVER V1,2,4,0003 MfgHJd 2015 12 11 11:13 PGM / RUN BY / DATE ";
  5. preg_match_all($re, $str, $matches);
  6. $cnt = count($matches[0]);
  7. $arr = array();
  8. for ($i = 0; $i < $cnt; $i++) {
  9. $arrAdd = array();
  10. $arrAdd[$matches[4][$i].trim()] = $matches[1][$i];
  11. $arrAdd[$matches[5][$i]] = $matches[2][$i];
  12. $arrAdd[$matches[6][$i]] = $matches[3][$i];
  13. array_push($arr, $arrAdd);
  14. }
  15. print_r($arr);
Success #stdin #stdout #stderr 0.02s 24448KB
stdin
Standard input is empty
stdout
2Array
(
    [0] => Array
        (
            [PGM] => DER V3,0,0,3323
            [RUN BY] => Xkisjd
            [DATE] => 2014 02 25 05:23
        )

    [1] => Array
        (
            [PGM] => VER V1,2,4,0003
            [RUN BY] => MfgHJd
            [DATE] => 2015 12 11 11:13
        )

)
stderr
PHP Warning:  trim() expects at least 1 parameter, 0 given in /home/OvIqTf/prog.php on line 11
PHP Warning:  trim() expects at least 1 parameter, 0 given in /home/OvIqTf/prog.php on line 11