PHP读取TXT文件

时间:2018-09-10 07:54:18

标签: php laravel laravel-5

我有一个这样的txt文件

SELL: num:1 rev(D:26048557 G:0) $D:150240888 $G:0 [08/10 18:05]
    - iybom01_10[100367586426880]
SELL: num:1 rev(D:26048557 G:0) $D:176289445 $G:0 [08/10 18:05]
    - iybom01_10[100367586426880]
BUY: num:7 pay(D:6716644 G:0) $D:169572801 $G:0 [08/10 18:08]
    + ipahp08_99_@ff[0]
    + ipahp08_99_@ff[0]
    + ipahp08_99_@ff[0]
    + ipahp08_99_@ff[0]
    + ipafp08_99_@ff[0]
    + ipasp04_99_@ff[0]
    + ipahp08_99_@ff[0]
BUY: num:5 pay(D:15784199 G:0) $D:153788602 $G:0 [08/10 18:09]
    + iharb35_747_@7ff55555[0]
    + iuarb35_0_@7ff55555[0]
    + ilarb35_0_@7ff55555[0]
    + igarb35_0_@7ff55555[0]
    + isarb35_0_@7ff55555[0]

我为获取字符串“ BUY”和“ SELL”创建了一个php脚本,但我只能显示类似的结果

Line 279: BUY: num:7 pay(D:6716644 G:0) $D:169572801 $G:0 [08/10 18:08] 

我的php代码

$lines = file('history/5.Log_History/Item/20180810/17/1696_175432.his');
$matches6 = preg_grep('/BUY/', $lines);
echo "BUY ITEM : " .count($matches6)." matches found.\n<br>";
foreach ($matches6 as $line => $contents) {
    echo "Line ".($line).": ".$contents."\n<br>";
}

我想要这样的输出

Line 279: BUY: num:7 pay(D:6716644 G:0) $D:169572801 $G:0 [08/10 18:08] 
    + iharb35_747_@7ff55555[0]
    + iuarb35_0_@7ff55555[0]
    + ilarb35_0_@7ff55555[0]
    + igarb35_0_@7ff55555[0]
    + isarb35_0_@7ff55555[0]

我必须如何编辑我的php脚本?

0 个答案:

没有答案