Wolf wrote:
/////////////////////////
 $filename=""; // Name of your CSV file
 $file_path = ""; // whatever your files are pathed
 $filename = $file_path.$filename;
 $handle = @fopen($filename, "r");
 $k=0;
 $entry = $file_path . "entry_file.txt"; // I use this to make a new entry file
 $entry_file = fopen($entry, 'w');
 $file_data = "dummy";
 if (!$entry_file){die("Unable to open $entry_file");}
 if ($handle)
 {
  echo "$filename opened successfully!<BR>";
  flush();
while (!feof($handle)) {

Don't forget your comma

        $row = fgets($handle, 4096);
        $data = "{$user_name},{$row}";
        fwrite($entry_file, $data);
        echo "{$data} written to {$row}\n";
        flush();

  }
 }
 fclose($handle);
 fclose($entry_file);
}
else
{ die("Error opening $filename"); }

/////////////////////////


---- pere roca <[EMAIL PROTECTED]> wrote:
  hi folks,
I have a CSV file. Data is separated by ','. For example:
  -94.86524,42.059444,A,B,X
  -96.86524,42.059444,A,B,Y1
-99.86524,42.059444,A,B,C1
  I want to interactively insert the user_name (passed by a php variable)
into the first "field" to insert then on my DataBase.
  Peter,-94.86524,42.059444,A,B,X
  Jan,-96.86524,42.059444,A,B,Y1
  ...
  I know there is a command (fwrite) to write, but I can't figure out how to
start with it... Afet open csv, etc. I think I should first check when there is a "return"
(we change of file), then I add the "user_name" parameter and repeat it as
long as there is some record. Any workaround or code doing something similar for a newbie in php,
please?
  Thanks,

   Pere
--
View this message in context: 
http://www.nabble.com/manipulating-CSV-files-tf4548721.html#a12980387
Sent from the PHP - General mailing list archive at Nabble.com.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to