I am having difficulty replacing a number I have stored in a text file, with several tab delimiters separating each value. You can see my entries file below the code to better understand how it is set up. I used a guestbook php script set up for me to do this, and now I just need to add one to a value placed in this text file. Here is the code I have so far, with the main idea of it copied from something similar to this already in the guestbook. If you could help me out, that would be fantastic. Thanks so much in advance! P.S. The user would click a link that would begin the php trying to change the value of the number in the text file, because the link is "myscript.php?i=2" and the variable i is the number of the post that i want to change the variable in, beginning at 0. If you need any more info, please ask. Thanks! Contents of myscript.php: <?php $numOfEntry = isset($_POST['i']) ? intval($_POST['i']) : false; if ($numOfEntry === false) { problem('You have not clicked the correct link, just tried to go to the file yourself. Error.'); } $myline = array(0=>'',1=>'',2=>'',3=>'',4=>'',5=>'',6=>'',7=>'',8=>''); $lines = file('entry file location here.txt'); $myline = explode("\t",$lines[$numOfEntry]); foreach ($myline as $k=>$v) { $myline[$k]=rtrim($v); } $actualstring = $myline[8]; $actualnum = (int)$actualstring; $numplusone = ($actualnum+1); $numplusonestr = strval($numplusone); $myline[8] = $numplusonestr; $lines[$num] = implode("\t",$myline)."\n"; $lines = implode('',$lines); $fp = fopen('entry file location here.txt','wb') or problem('Entry file is not writable.'); fputs($fp,$lines); fclose($fp); ?> Code (php): Here is the file containing the entries. There is also one attached. Name of Poster (4 tabs here) Text of post. (1 tab here) Date, such as Febuary 2, 2010 (1 tab) 0 (1 tab) 0 (1 tab) 0 (1 tab) IP Address Name of Poster (4 tabs here) Text of post. (1 tab here) Date, such as Febuary 2, 2010 (1 tab) 0 (1 tab) 0 (1 tab) 0 (1 tab) IP Address Name of Poster (4 tabs here) Text of post. (1 tab here) Date, such as Febuary 2, 2010 (1 tab) 0 (1 tab) 0 (1 tab) (Here would be the numeric value that I would want to increase by one) (1 tab) IP Address Name of Poster (4 tabs here) Text of post. (1 tab here) Date, such as Febuary 2, 2010 (1 tab) 0 (1 tab) 0 (1 tab) 0 (1 tab) IP Address Name of Poster (4 tabs here) Text of post. (1 tab here) Date, such as Febuary 2, 2010 (1 tab) 0 (1 tab) 0 (1 tab) 0 (1 tab) IP Address Code (text):
This is silly. Use a database; it's much easier and performs far better. As your text file grows, accessing it will become slower and slower until eventually the server CPU melts down and forms a black hole which will swallow up the earth.