2016-05-02 10 views
0

私は最後の5行を読みたいtxtファイルを持っています。#は#で始まり#で終わります。 txtファイルは次のようになります。PHPでtxtファイルの最後の5行を読む方法#

#STA:00008;TM:04/30/2016,17:56:03;C:02;V:0.02;AD15:00000;AD16:00000;AD17:00000;AD18:00000;DI:001110;DO:0000;# 
#STA:00008;TM:04/30/2016,17:56:32;C:03;V:0.02;AD15:00000;AD16:00000;AD17:00000;AD18:00000;DI:001110;DO:0000;# 
#STA:00008;TM:04/30/2016,17:57:02;C:04;V:0.02;AD15:00000;AD16:00000;AD17:00000;AD18:00000;DI:001110;DO:0000;# 

のコメント:

$file = file_get_contents("F:\RTU GSM\S220 GSM GPRS Remote Controller PC Configurator V2.1\profile\severtxt.txt"); 
$station = explode(";TM:",$file); 
$keywords = preg_split("/;+/", $file); 
print_r($keywords); 
+1

簡単でも、あなたが立ち往生している正規表現を必要としないのですか? – anubhava

+0

$ file = file_get_contents( "F:\ RTU GSM \ S220 GSM GPRSリモートコントローラPCコンフィギュレータV2.1 \ profile \ severtxt.txt"); $ station = explode( "; TM:"、$ file); $ keywords = preg_split( "/; + /"、$ file); print_r($ keywords); –

答えて

0

いくつかの方法、1は次されている:

$file = @file("your_file_here.txt"); 
$i = count($file); 
for ($j=$i-5;$j<$i;$j++) { 
    $columns = explode(';', $file[$j]); 
    print_r($columns); 
} 
+0

この行を#から#に1列に分割したい –

関連する問題