vivalaraza Posted April 1, 2007 Share Posted April 1, 2007 Hey after trying to find the error for ages i give up for now, well if you can find it and show me i will be greatly appreciated: $txt = "random/new.txt"; $i= 1; $line[0] = "somedata...."; // this gets the info from the form and adds the line to the first value of the array $fp = fopen($txt,"rb"); // need to use rb cause windows ////then the file is read into the array starting from $line[1] while(!feof($fp)) { $line[$i] = fgets($fp); if (empty($line[$i])) { unset($line[$i]); $i = $i - 1; } $i++; } fclose($fp); /// now the whole array is read back into the file $i = 0; $total = count($line); $fp = fopen($txt,"wb"); //need to use rb cause windows while ($i < $total) { if ($i <> $total - 1) { fwrite($fp,"$line[$i]\r\n"); //need to use \r\n cause windows } else { fwrite($fp,"$line[$i]"); } $i++; } fclose($fp); } I want to format it so i can make the first line in the text file be the contents of the form that was just processed, after clicking the button the first time to process the form, it was fine,the 2nd time to process the form its fine, the 3rd time i clicked the button the text file looks something like this: somedata somedata // and that annoying irrating space in the text file appears somedata Link to comment https://forums.phpfreaks.com/topic/45143-having-some-problems-with-reading-and-writing-in-files/ Share on other sites More sharing options...
vivalaraza Posted April 1, 2007 Author Share Posted April 1, 2007 guess im going to have to figure it out myself, as usually eventually i will figure it out just in time Link to comment https://forums.phpfreaks.com/topic/45143-having-some-problems-with-reading-and-writing-in-files/#findComment-219284 Share on other sites More sharing options...
vivalaraza Posted April 2, 2007 Author Share Posted April 2, 2007 i fixed it told ya Link to comment https://forums.phpfreaks.com/topic/45143-having-some-problems-with-reading-and-writing-in-files/#findComment-219828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.