Be a Supporter!

file writing to start

  • 256 Views
  • 4 Replies
New Topic Respond to this Topic
Snubby
Snubby
  • Member since: Dec. 4, 2004
  • Offline.
Forum Stats
Member
Level 21
Game Developer
file writing to start 2006-12-03 21:09:15 Reply

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
Response to file writing to start 2006-12-03 21:10:58 Reply

It would help if you told us what language you are using :)


BBS Signature
Afro-Ninja
Afro-Ninja
  • Member since: Mar. 2, 2002
  • Offline.
Forum Stats
Moderator
Level 44
Game Developer
Response to file writing to start 2006-12-03 21:15:44 Reply

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


BBS Signature
Snubby
Snubby
  • Member since: Dec. 4, 2004
  • Offline.
Forum Stats
Member
Level 21
Game Developer
Response to file writing to start 2006-12-03 21:28:14 Reply

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
Response to file writing to start 2006-12-04 02:56:57 Reply

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.