Hi all, I have a problem related to text file. I need to read the data from a text file, which is not completely seperated by whitespace, comma, or whatever. To be more precisely, the file makes use of "number of character" to seperate the fields.
The following is the sample data of my text file, please see the attached text file
datetime ID NAME COUNTRY AGE GENDER
=============================================
09/09/2004 0:00:00 AEF0021 JOHN USA 161
29/08/2004 0:00:00 AEF0021 JOE CANADA 451
AEF0021 SARAH ITALY 232
17/12/2004 0:00:00 AEF0021 DAVID GERMANY 1
I tried to use fscanf to extract those fields but I had no luck
while ($userinfo = fscanf($handle, "%19s\r\n")) {
list($datetime) = $userinfo;
echo "$userinfo<br />";
}
It only printed the date and ignored the time. The date and time are actually the same field value. Furthermore, some of the values like 161 is composed of 2 values as well(16 is age and 1 is male). Any idea how can I get the values out? Thank you very much