需要帮助从提取的记录创建数组数据

时间:2015-11-02 08:06:17

标签: php arrays web-scraping

我附加了文本文件(Text file link),并且还提到了如下:

     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

有没有办法在数组中获取记录,如下所述:

[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....

我试图通过自己收集数据,如下所述:

$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] 
    }
}

然后按空间爆炸它们但爆炸后的所有数组元素($ date,$ days,$ events,$ times)都在不同的数组键中,因此无法存储在单个数组中。请为此建议良好的逻辑。

0 个答案:

没有答案