Rahul Tripathi Rahul Tripathi - 6 months ago 9
Javascript Question

I wana get only those string from file which start with #STA AND end With ;# from txt file using php

**#STA:00007;TM:04/30/2016,19:35:32;C:81;V:0.02;AD15:00000;AD16:00000;AD17:00000;AD18:00000;DI:001110;DO:0000;#


STA:00008;TM:04/30/2016,19:37:02;C:15;V:0.04;AD01:00000;AD02:00000;AD03:00000;AD04:00000;AD05:00000;AD06:00000;AD11:35.25;AD12:-0.06;AD15:00000;AD16:00000;AD17:00000;AD18:00000;PU01:00000000;PU02:00000000;PU03:00000000;PU04:00000000;




**
i want to ignore the last line which i have blockquoted and i want to get only those line which ends with ;# character.

Answer

http://www.phpliveregex.com/p/fCv

preg_match("/(\#STA.*\;\#)/", $input, $output);

Edit: maybe it should be preg_match_all?

Edit2: http://www.phpliveregex.com/p/fCx

preg_match_all("/(\#STA.*?\;\#)/", $input, $output);
For($i=0;$i<=count($output[1]);$i++){
   Echo $output[1][$i];
   //$str .= $output[1][$i];
}
Comments