There is no need to reinvent the wheel here.  MySQL has a built in function
to do exactlywhat you want to do.

Check out LOAD DATA INFILE here: http://www.mysql.com/doc/L/O/LOAD_DATA.html

Fred

Yoed Anis <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hey Guys,
>
> I'm having a trouble I can't seem to solve and hoped maybe one of you
might
> take a look and see if you can help me.
> (If you don't want to learn my approach just skip to the bottom to help me
> with the final bit.. skip to "hear")
>
> What I want to do is open the text file testtext.txt (attached) and input
> all the information from one row (divided into fields and colum) and input
> that into a database (mysql)... I thought the easiest way to do this is
> split the fields in the row into an array... since they are all seperated
by
> spaces.... If only it was so easy. This is what I did:
>
> <code>
> $count=0;
> $fd = fopen ("./Testtext.txt", "r");
> while (!feof ($fd)) {
>     $buffer = fgets($fd, 4096);
>     $count++;
>     if($count > 2 && $count < 4){
>      $thearray=split("[ ]+", $buffer);
>      $maxi=count($thearray);
>      for($i=0; $i<$maxi; $i++){
>       echo "$thearray[$i] $i ";
>      }
>      echo "<br>";
>     }
> }
> </code>
>     Ok now the echo statement above prints the following:
>     07/29/2001 12:00 0 a 28.6 28.6 28.5 0.00000 31.2 -- 0 0.0 0.0 1018.8
3.1
> 6.3 N 28.0 1.9 0.00 0.0 74 23.4 32.1 10 12.00 1
>     It looks all good till well the 0 (where did that come from?) after
the
> 12:00! But upon further code writing:
> <code>
> $wdate=$thearray[0];
> $wtime=$thearray[1];
> $wtimeampm=$thearray[2];
>
> echo "<BR>The date of the data is : $wdate taken at the time of $wtime
> $wtimampm";
> </code>
>     that prints:
> The date of the data is : 07/29/2001 12:00 taken at the time of a 28.6
28.6
> 28.5 0.00000 31.2 -- 0 0.0 0.0 1018.8 3.1 6.3 N 28.0 1.9 0.00 0.0 74 23.4
> 32.1 10 12.00
> It looks as the array is having trouble splitting the date from the time
> (why there is a space there!!??) and makes all the other data into one or
> two other parts of the area (instead of the many fields).
>
> --HEAR--
> So I've narrowed it to this:      $thearray=split("[ ]+", $buffer);
> Does this look like what I should use to separate all my data in the
array?
> It gets this data from one row in the file testtext.txt which looks like
all
> fields are separated by at least one space. What should I do?
>
> Thanks a bunch,
> Yoed
>
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to