rhyspaterson Posted May 29, 2007 Share Posted May 29, 2007 Hey guys. I have a file that i open with fopen a+, meaning when i open the file it places the pointer at the end of the file and writes from there. I then write an array to the file. My only problem is, when i place the pointer at the end of the file it looks like this. <bt>600</bt> <iregno>123456789</iregno> <users> <un>1</un> <u1> <n>username1</n> <ema>username1@domain.com<ema> <s>password</s> <t>status</t> <p>profile name</p> <cat>000000000000000000000000000000000</cat> </u1> </users><<<<< ------ pointer is here and then when i append my data, file looks like this <bt>600</bt> <iregno>123456789</iregno> <users> <un>2</un> <u1> <n>username</n> <ema>username@domain.com<ema> <s>password</s> <t>status</t> <p>profile name</p> <cat>000000000000000000000000000000000</cat> </u1> </users><u2> <n>username2</n> <ema>username2@domain.com<ema> <s>password</s> <t>status</t> <p>profile name</p> <cat>000000000000000000000000000000000</cat> </u2> </users> the bad part being </users><u2> i would like to overwrite the last line and continue adding my data. Is this possible in any way? Thanks so much, /Rhys Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 29, 2007 Share Posted May 29, 2007 this look smore like a prime candidate for an xml file you can at the very least use the same methods for managing this file have a look at simplexml if you are using php 5 or DOMxml for php4... Quote Link to comment Share on other sites More sharing options...
rhyspaterson Posted May 29, 2007 Author Share Posted May 29, 2007 thats what i told my boss, but based on what they are using, it *has* to be a .txt file.. Quote Link to comment Share on other sites More sharing options...
rhyspaterson Posted May 29, 2007 Author Share Posted May 29, 2007 it looks like fseek is the way to go, but i am just not quite sure how to implement it.. /edit figured it out. $fp = fopen($local_file, "r+") or die ("Can't open user file"); fseek($fp, -8, SEEK_END); foreach($userArray as $val) { fwrite($fp, $val); } fclose($fp); thanks lads. 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.