Hello René, The problem is the implode() function call (you are telling it concatenate all of the lines into one). This is not tested, but try replacing:
> $fcontents_string = implode('', $fcontents); > > $fp = fopen($name.".db", "w+"); > fwrite($fp,$fcontents_string); with: for ($i=0; $i <= count($fcontents); $i++) fwrite($fp, $fcontents[$i]); HTH, John >This problem has been driving me insane. I have a little script that let's >users enter data into a form, which then gets appended to a file (table) as >a line (row). The adding part of the script works fine--and by remembering >to add a "\n" at the end of each row, when the file (table) is read, PHP >automagically figures out that each line is actually a row (thanks to the >"\n"), and organizes the array accordingly (each line becoming an element in >the array). The file thus displays fine. So far, so good. > >The problem arrises when I try to update a row (line) in the table (file). >The good: The line break character "\n" at the end of row being updated >DOES get written properly. The bad: The line break characters for all the >other rows of the table (which I'm not trying to update) disappear and/or >CHANGE to a different, inscrutable character (square) when the whole >array-turn-string gets written to the file. > >I realize this is confusing without the example code, so here it is... > >THE TABLE (FILE.DB) BEFORE THE UPDATE >======================================================================== >19 Oct 2001, 17:56|Movie|War and Peace|800||Ready|redoctober| >19 Oct 2001, 17:56|Movie|Hamlet|500||Ready|redoctober| >19 Oct 2001, 17:56|Movie|Les Miserables|600||Ready|redoctober| >19 Oct 2001, 17:57|Movie|Fahrenheit 451|||Ready|redoctober| >======================================================================== > >THE USER CHANGES HAMLET TO HENRY V, THEN CLICKS SUBMIT >======================================================================== >19 Oct 2001, 17:56|Movie|War and Peace|800||Ready|redoctober| 19 Oct 2001, >17:56|Movie|Henry V|500||Ready|redoctober| >19 Oct 2001, 17:56|Movie|Les Miserables|600||Ready|redoctober| 19 Oct 2001, >17:57|Movie|Fahrenheit 451|||Ready|redoctober| >======================================================================== > >Notice how the first two and last two lines, where there used to be a line >break, now run together--and only the updated row/line has a line break at >the end? WHY?!?!?!?!?!?! =:-(O) > >And here's my crappy-as-usual code that handles the new/update functions >(thanks to everyone who have helped me get it to even this state): >======================================================================== >if (isset($submit)) { > > if (isset($update)) { // UPDATE > $affected0 = $started; > $affected1 = $type; > $affected2 = $title; > $affected3 = $size; > $affected4 = $res; > $affected5 = $status; > $affected6 = $by; > $updatedstring = $affected0 . "|" . $affected1 . "|" . $affected2 . "|" . >$affected3 . "|" . $affected4 . "|" . $affected5 . "|" . $affected6 . "|" . >"\n"; > > $fcontents = file($name.".db"); > $fcontents[$update] = $updatedstring; > $fcontents_string = implode('', $fcontents); > > $fp = fopen($name.".db", "w+"); > fwrite($fp,$fcontents_string); > fclose($fp); > > } else { // ADD > $fp = fopen($name.".db", "a"); > $now = date("j M Y, H:i"); > $by = $name; > $common=$now . "|" . $type . "|" . $title . "|" . $size . "|" . $res . >"|" . $status ."|". $by . "|" . "\n"; > fwrite($fp,$common); // write to the file > fclose($fp); // close the file > } >} >======================================================================== > >A million thanks if you can help me crush this bug! > >--- >Rene Fournier >[EMAIL PROTECTED] > > >-- >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] -- /* SteeleSoft Consulting John Steele - Systems Analyst/Programmer * We also walk dogs... Dynamic Web Design PHP/MySQL/Linux/Hosting * www.steelesoftconsulting.com [EMAIL PROTECTED] */ -- 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]