I have text file as attached(Text file link) and also mentioned as below:
053722 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
ULUSOY Pe Cu Ct Pa Pt Sa Ca Pe Cu Ct Pa Pt Sa Ca Pe Cu Ct Pa Pt Sa Ca Pe Cu Ct Pa Pt Sa Ca Pe Cu Ct
YAVUZ BARBAROS IBB IBB AG AG IBB IBB OME DY DY DY IBB OME OME OME AG AG AG IBE III III III III III III III III III III III III III
Uc Tr/Fl/Snf: C/738/C1
Uc Sr/Lmt U: 41:35/0:00 IST IST IST IST
Lnd Krt Bit Tr: 03DEC2016 06:00 06:00 06:00 06:00
14:00 14:00 14:00 14:00
Is there any way to fetch records in array like as mentioned below:
[0] => Array
(
[date] =01
[day] = Pe
[name] =IBB
[sector_to] =""
[arr_time] = ""
[dep_time] =""
)
.
.
.
[6] => Array
(
[date] = 07
[day] = ca
[name] = OME
[sector_to] =IST
[arr_time] =06:00
[dep_time] =14:00
)
.
so on....
I tried to collect data by my self as mentioned below:
$data = array(); $dates = array(), $days = array(); $events =array();
$times = array();
$lines = file('thy-roster.txt');
foreach ($lines as $line) {
if (preg_match('/(\d{2})\s/', $line, $matches)) {
$dates = $matches[0]
}
if (preg_match('/([a-z]{2})\s/', $line, $matches)) {
$days = $matches[0]
}
if (preg_match('/([A-Z]{3})\s/', $line, $matches)) {
$events = $matches[0]
}
if (preg_match('/(\d{1,2}:\d{2})\s/', $line, $matches)) {
$times = $matches[0]
}
}
Then explode them by space but all array element after exploade($dates,$days, $events, $times) are in different array keys so unable to store in single array.Please advice good logic for this.