I want to add text string at the end of the text file. I used "a+" for it but it delete all the content and than enters text to it. So please help.

kirtan_thakkar
Recommended Answers
Jump to PostJust use dot (.)
<?php $text1 = "World"; echo "Hello ".$text1; //The output will be Hello World $text2="Hello"; echo $text2." World"; //The output will be Hello World ?>
Jump to Post$f = fopen( 'filename.txt', 'a' ); fwrite( $f, 'something' ); fclose( $f );
Jump to PostHi,
Replace the 3rd line with the below code.file_put_contents($file,$data,FILE_APPEND);
The third parameter need to be set in file_put_contents to append with existing data. otherwise it would overwrite the existing file contents. check the manual
All 9 Replies
Javvy -1 Junior Poster

kirtan_thakkar
Javvy -1 Junior Poster
lyrico 23 Junior Poster in Training
Javvy -1 Junior Poster
smantscheff 265 Veteran Poster

kirtan_thakkar
paulrajj 6 Junior Poster
msnadz 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.