tobeyt23 Posted September 29, 2010 Share Posted September 29, 2010 I need to open a template file change a text var and then save the file as something new. How can I do this? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 29, 2010 Share Posted September 29, 2010 fopen() and fread() the file, or use file() if the lines are distinct. find the text var to change, then save the updated content in a new file with a new fopen()/fwrite(). Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 29, 2010 Share Posted September 29, 2010 You can also use file_get_contents and file_put_contents for reading & writing the file. Ken Quote Link to comment Share on other sites More sharing options...
tobeyt23 Posted September 29, 2010 Author Share Posted September 29, 2010 This is what a came up with: <?php $_file = 'text.txt'; $_contents = file_get_contents($_file); $_replace = "Replaced"; $_find = '###FIND###'; $_contents = str_replace($_find, $_replace, $_contents); $_fo = fopen($_file,"w") or die ("Error editing."); fputs($_fo,$_contents); fclose($_fo) or die ("Error Closing File!"); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.