text.txt
-
Datalogs:
-
Date: 2007/6/11
-
Time: 13:9:3
-
Device ID: Data Logger
-
About total Numbers: 001891
-
===================
-
=====================
-
Record: 1
-
Event Type: 3
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 37.527237
-
Latitude: 1.342335
-
Longitude: 103.776921
-
Altitude: 0.000000
-
PDOP: 50.000000
-
HDOP: 50.000000
-
Satellite No: 3
-
Speed(KMs/hr): 0.000000
-
Direction: 0.000000
-
=====================
-
Record: 2
-
Event Type: 1
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 42.526936
-
Latitude: 1.342367
-
Longitude: 103.776861
-
Altitude: 0.000000
-
PDOP: 50.000000
-
HDOP: 50.000000
-
Satellite No: 3
-
Speed(KMs/hr): 0.000000
-
Direction: 0.000000
-
=====================
-
Record: 3
-
Event Type: 1
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 47.526634
-
Latitude: 1.342375
-
Longitude: 103.776858
-
Altitude: 0.000000
-
PDOP: 50.000000
-
HDOP: 50.000000
-
Satellite No: 3
-
Speed(KMs/hr): 0.000000
-
Direction: 0.000000
-
=====================
-
Try to modify this script as per your requirement.
read_text.php
-
<?php
-
$filename = "text.txt";
-
$fd = fopen ($filename, "r");
-
$contents = fread ($fd,filesize ($filename));
-
fclose ($fd);
-
-
$delimiter = "=====================";
-
$splitcontents = explode($delimiter, $contents);
-
-
foreach( $splitcontents as $record )
-
{
-
-
echo "$record<hr>";
-
}
-
-
?>
-
this is the same method your going to use with your new problem..
take not of this..
[PHP]$delimiter = "=====================";
$splitcontents = explode($delimiter, $contents);[/PHP]
this is how you extract it from text file...
delimiter is the one that separates your data...
in this format, the delimiter you going to extract is this
$delimiter = "====================="; - Record: 2
-
Event Type: 1
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 42.526936
-
Latitude: 1.342367
-
Longitude: 103.776861
-
Altitude: 0.000000
-
PDOP: 50.000000
-
HDOP: 50.000000
-
Satellite No: 3
-
Speed(KMs/hr): 0.000000
-
Direction: 0.000000
-
=====================
-
Record: 3
-
Event Type: 1
-
Year: 2007
-
Month: 6
-
Day: 7
-
Hour: 5
-
Minute: 9
-
Second: 47.526634
-
Latitude: 1.342375
-
Longitude: 103.776858
-
Altitude: 0.000000
-
PDOP: 50.000000
-
HDOP: 50.000000
-
Satellite No: 3
-
Speed(KMs/hr): 0.000000
-
Direction: 0.000000
results to this...
// first data... inside an array
Record: 2
Event Type: 1
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 42.526936
Latitude: 1.342367
Longitude: 103.776861
Altitude: 0.000000
PDOP: 50.000000
HDOP: 50.000000
Satellite No: 3
Speed(KMs/hr): 0.000000
Direction: 0.000000
// 2nd data inside an array
Record: 3
Event Type: 1
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 47.526634
Latitude: 1.342375
Longitude: 103.776858
Altitude: 0.000000
PDOP: 50.000000
HDOP: 50.000000
Satellite No: 3
Speed(KMs/hr): 0.000000
Direction: 0.000000
now... to extract each data inside.. so that it will fit in your table with their corresponding fields..
use delimiter
$delimiter = "\n"; means new line..
[PHP]$delimiter = "\n";
$data_contents = explode($delimiter, $splitcontents[$i]);[/PHP]
//notice that
$splitcontents[$i] is in array already.. 'cause your doing this with an array inside an array..
Record: 2
Event Type: 1
Year: 2007
Month: 6
Day: 7
Hour: 5
Minute: 9
Second: 42.526936
Latitude: 1.342367
Longitude: 103.776861
Altitude: 0.000000
PDOP: 50.000000
HDOP: 50.000000
Satellite No: 3
Speed(KMs/hr): 0.000000
Direction: 0.000000
now the result is would line by line.. now use the same method.. but with a delimiter
$delimiter = ':';
remember.. its an array within an array... have fun.. ^___^