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? 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); 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 ? 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?? 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. 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."; 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
Archived
This topic is now archived and is closed to further replies.