I am currently attempting to drag some information out of a .txt file using a php script. I have been reading about regex's and thought this would be ideal. To give you some idea the format of the text in the .txt file is as follows:
Data Rate: 20 Hz
Digital I/O Channels:
CH1_IN,0,CH2_OUT,1,CH3_IN,0,CH4_OUT,1,CH5_IN,0,CH6_IN,0,CH7_IN,0,CH8_OUT,0,CH9_IN,0,
CH10_IN,0,CH11_OUT,1,CH12_IN,0,CH13_IN,0,CH14_IN,0,CH15_IN,0,CH16_IN,0,
QEA: Enabled
I am trying to pull out the following detail for each channel:
CH(number)_(IN or OUT),(integer)
As described in various posts and some tutorials I have tried using preg_split but haven't been able to get it to work as I want. My understanding is that something like that shown below should work, although it is likely I have not used it correctly:
$log_file_data = file_get_contents('Log.txt');
$channel_detail = preg_split("/CH[0-9]{2}_[A-Z],[0-1]{1}/",$log_file_data);
My intention is that this would split the text nicely into portions as described earlier but as expected it just pretty much spews out the complete text file. Am I using the correct method or does it not suit what I am looking to achieve?
Any guidance would be appreciated.