Originally posted by ajaxrand
take not of this..
[PHP]$delimiter = "============== =======";
$splitcontents = explode($delimi ter, $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 = "============== =======";
Code:
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
// 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($delimi ter, $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.. ^___^
Comment