tyra Posted May 21, 2009 Share Posted May 21, 2009 Hi everyone! If i have file where is data 1;0;1;0 then how to add there +1 for the first one and +1 for the last one? Quote Link to comment https://forums.phpfreaks.com/topic/159084-solved-add-data-to-database/ Share on other sites More sharing options...
premiso Posted May 21, 2009 Share Posted May 21, 2009 $file = file('datafile.txt'); $fh = fopen('datafile.txt', "w+"); // truncate file and open for writing foreach ($file as $line) { $inputs = explode($line); $inputs[0]++; // add1 to the first number $inputs[3]++; // add 1 to the last number fwrite($fh, implode(";", $inputs) . "\n"); // write back to file on a new line } fclose($fh); Quote Link to comment https://forums.phpfreaks.com/topic/159084-solved-add-data-to-database/#findComment-838958 Share on other sites More sharing options...
tyra Posted May 21, 2009 Author Share Posted May 21, 2009 Thank you! Is there any possibility to count lines of database file ? Quote Link to comment https://forums.phpfreaks.com/topic/159084-solved-add-data-to-database/#findComment-839391 Share on other sites More sharing options...
BobcatM Posted May 21, 2009 Share Posted May 21, 2009 Count the lines if your text file?? Quote Link to comment https://forums.phpfreaks.com/topic/159084-solved-add-data-to-database/#findComment-839398 Share on other sites More sharing options...
tyra Posted May 22, 2009 Author Share Posted May 22, 2009 jep. Quote Link to comment https://forums.phpfreaks.com/topic/159084-solved-add-data-to-database/#findComment-839581 Share on other sites More sharing options...
premiso Posted May 23, 2009 Share Posted May 23, 2009 $file = file('datafile.txt'); $count = count($file); echo "There are {$count} number of lines."; Quote Link to comment https://forums.phpfreaks.com/topic/159084-solved-add-data-to-database/#findComment-840704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.