By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

How to append new data in beginning of the text file in php

P: 65
Hello,

I have problem is when i append new data in text file always append at the last of the text file. Am i can append the new data in beginning of the text file? Mean when i have update data the text file and always write at the beginning of the text file and the previous data at the below of the new data..

Can anyone have idea about it?

Thanks in advance...
Dec 14 '07 #1
Share this Question
Share on Google+
1 Reply


nathj
Expert 100+
P: 938
Hello,

I have problem is when i append new data in text file always append at the last of the text file. Am i can append the new data in beginning of the text file? Mean when i have update data the text file and always write at the beginning of the text file and the previous data at the below of the new data..

Can anyone have idea about it?

Thanks in advance...
Hi wish,

I don't know if there is a setting ton control this but one thing you could do is to take the contents of the file into a variable then define a new variable as new text plus the variable and then write it back to the file. In psuedo code:
Expand|Select|Wrap|Line Numbers
  1. $lcExistingText = fread(_file_) ;
  2. $lcNewContents = $lcNewText . $lcExistingText ;
  3. fwrite($lcNewContents) ;
  4.  
This is just psuedo code but hopefully explains the logic enough for you.

Cheers
nathj
Dec 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.