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++; 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? 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. 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; 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]); Link to comment https://forums.phpfreaks.com/topic/223773-converting-fread-to-int/#findComment-1156754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.