file writing to start
- Snubby
-
Snubby
- Member since: Dec. 4, 2004
- Offline.
-
- Forum Stats
- Member
- Level 21
- Game Developer
say for some crazy reason I wanted to write to the start of a file, would I do something with arrays? I'm pretty sure I can do that, but is there an easier way?
- DFox
-
DFox
- Member since: Aug. 9, 2003
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
It would help if you told us what language you are using :)
- Afro-Ninja
-
Afro-Ninja
- Member since: Mar. 2, 2002
- Offline.
-
- Send Private Message
- Browse All Posts (13,458)
- Block
-
- Forum Stats
- Moderator
- Level 44
- Game Developer
At 12/3/06 09:12 PM, SpamBurger wrote: <?php
$oldcontent=file_get_contents("file.ext");
$fr=fopen("file.ext","w");
fwrite($fr,'new content '.$oldcontent);
fclose($fr);
?>
'w' starts at the beginning and truncates the file, if you use 'r+' it will place the pointer at the beginning and you wont have to read in the contents of the old file first
- Snubby
-
Snubby
- Member since: Dec. 4, 2004
- Offline.
-
- Forum Stats
- Member
- Level 21
- Game Developer
At 12/3/06 09:10 PM, DFox wrote: It would help if you told us what language you are using :)
Woah sorry, that totally slipped my mind! I feel so stupid... PHP 4!
- henke37
-
henke37
- Member since: Sep. 10, 2004
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
Why does everybody keep opening and closing the same file? Just open it once and do what you need.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.



