brenhein Posted January 8, 2011 Share Posted January 8, 2011 Hello. I need help adding a text file content by one and then saving. My current code is $myFile = "serving"; $fh = fopen($myFile, 'w+') or die("can't open file"); $conv = fread($fh, 4); $stringData = $conv++; fwrite($fh, $stringData); fclose($fh); I was told this would work, but of course, it doesn't. It always returns 1. I also tried casting it as an int by using $stringData = (int) $conv++; Quote Link to comment https://forums.phpfreaks.com/topic/223773-converting-fread-to-int/ Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 Does that file contain just one number, and nothing else? Quote Link to comment https://forums.phpfreaks.com/topic/223773-converting-fread-to-int/#findComment-1156649 Share on other sites More sharing options...
brenhein Posted January 8, 2011 Author Share Posted January 8, 2011 The text file contains just a number. Quote Link to comment https://forums.phpfreaks.com/topic/223773-converting-fread-to-int/#findComment-1156650 Share on other sites More sharing options...
sasa Posted January 8, 2011 Share Posted January 8, 2011 change $stringData = $conv++; to $stringData = $conv+1; or $stringData = ++$conv; Quote Link to comment https://forums.phpfreaks.com/topic/223773-converting-fread-to-int/#findComment-1156750 Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 Or to simplify it a little bit $myfile = 'serving'; $num = file($myfile); $num[0] = $num[0] + 1; file_put_contents($myfile, $num[0]); Quote Link to comment https://forums.phpfreaks.com/topic/223773-converting-fread-to-int/#findComment-1156754 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.