View Full Version : Can fwrite() write into, rather over?

02-22-2012, 08:56 AM
Hi all,

I have fwrite() writing to a text file called 'numbers.txt'. The text file content is "23".

I learn't fwrite() from the manual, so did:

f$fp = fopen('/opt/numbers.txt', 'w');
fwrite($fp, '1');
fclose ($fp);

I have used fwrite() to try and make the file content "123", but fwrite() writes over the content of the file, resulting in it just containing "1".

I couldn't find anywhere about writing into, rather over, and hoping someone could please help me out.

02-22-2012, 09:11 AM
$fp = fopen('/opt/numbers.txt', 'w');
Read the manual (http://php.net/fopen) regarding the different usages of the second parameter (mode)

02-22-2012, 09:17 AM
Hi. You were unable to assist, but thank you for trying.

02-22-2012, 10:41 AM
He helped you Noonga. Did you read the page he suggested you read? The use of W in your fopen will destroy the file. Something you would have discovered if you'd followed the link.